[PATCH] Replace regular code with appropriate calls to container_of()
authorRobert P. J. Day <rpjday@mindspring.com>
Sat, 10 Feb 2007 09:46:25 +0000 (01:46 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Sun, 11 Feb 2007 19:18:06 +0000 (11:18 -0800)
Replace a small number of expressions with a call to the "container_of()"
macro.

Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>
Acked-by: Paul Mackerras <paulus@samba.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/net/ppp_generic.c
drivers/s390/net/lcs.c
drivers/video/sa1100fb.h
include/linux/security.h
security/selinux/hooks.c

index c6de566188e4d6db66667b1855031d90b9dc8524..0986f6c843e6974d87298c3b5f87d444d594858f 100644 (file)
@@ -83,7 +83,7 @@ struct ppp_file {
        int             dead;           /* unit/channel has been shut down */
 };
 
-#define PF_TO_X(pf, X)         ((X *)((char *)(pf) - offsetof(X, file)))
+#define PF_TO_X(pf, X)         container_of(pf, X, file)
 
 #define PF_TO_PPP(pf)          PF_TO_X(pf, struct ppp)
 #define PF_TO_CHANNEL(pf)      PF_TO_X(pf, struct channel)
index b97dd15bdb9a1ecb7d0b15b3c6ffcbc49ff12200..ecca1046714efd213f57fce49a69bca391faf047 100644 (file)
@@ -1511,8 +1511,7 @@ lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
        LCS_DBF_TEXT(5, trace, "txbuffcb");
        /* Put buffer back to pool. */
        lcs_release_buffer(channel, buffer);
-       card = (struct lcs_card *)
-               ((char *) channel - offsetof(struct lcs_card, write));
+       card = container_of(channel, struct lcs_card, write);
        if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev))
                netif_wake_queue(card->dev);
        spin_lock(&card->lock);
@@ -1810,8 +1809,7 @@ lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
                LCS_DBF_TEXT(4, trace, "-eiogpkt");
                return;
        }
-       card = (struct lcs_card *)
-               ((char *) channel - offsetof(struct lcs_card, read));
+       card = container_of(channel, struct lcs_card, read);
        offset = 0;
        while (lcs_hdr->offset != 0) {
                if (lcs_hdr->offset <= 0 ||
index 0b07f6ae3367c286611695c9c7950c9afd2f0d56..48066ef3af05fa2356171a76932e8252b62b05e5 100644 (file)
@@ -110,9 +110,7 @@ struct sa1100fb_info {
 #endif
 };
 
-#define __type_entry(ptr,type,member) ((type *)((char *)(ptr)-offsetof(type,member)))
-
-#define TO_INF(ptr,member)     __type_entry(ptr,struct sa1100fb_info,member)
+#define TO_INF(ptr,member)     container_of(ptr,struct sa1100fb_info,member)
 
 #define SA1100_PALETTE_MODE_VAL(bpp)    (((bpp) & 0x018) << 9)
 
index 83cdefae993165cce7e8601dc127fcb520420161..c554f60f18e4e1b3399973360bed004c8affdcab 100644 (file)
@@ -492,7 +492,7 @@ struct request_sock;
  *     Note that the fown_struct, @fown, is never outside the context of a
  *     struct file, so the file structure (and associated security information)
  *     can always be obtained:
- *             (struct file *)((long)fown - offsetof(struct file,f_owner));
+ *             container_of(fown, struct file, f_owner)
  *     @tsk contains the structure of task receiving signal.
  *     @fown contains the file owner information.
  *     @sig is the signal that will be sent.  When 0, kernel sends SIGIO.
index 9eeab82719a2106ed9f4112371af1783d800d2c2..35eb8de892fc513bd187ad3c5acbce9cd271ebd1 100644 (file)
@@ -2654,7 +2654,7 @@ static int selinux_file_send_sigiotask(struct task_struct *tsk,
        struct file_security_struct *fsec;
 
        /* struct fown_struct is never outside the context of a struct file */
-        file = (struct file *)((long)fown - offsetof(struct file,f_owner));
+        file = container_of(fown, struct file, f_owner);
 
        tsec = tsk->security;
        fsec = file->f_security;