Skip to content

Commit b385a14

Browse files
Robert P. J. DayLinus Torvalds
authored andcommitted
[PATCH] Replace regular code with appropriate calls to container_of()
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>
1 parent 521dae1 commit b385a14

5 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎drivers/net/ppp_generic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct ppp_file {
8383
int dead; /* unit/channel has been shut down */
8484
};
8585

86-
#define PF_TO_X(pf, X) ((X *)((char *)(pf) - offsetof(X, file)))
86+
#define PF_TO_X(pf, X) container_of(pf, X, file)
8787

8888
#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
8989
#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)

‎drivers/s390/net/lcs.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,7 @@ lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
15111511
LCS_DBF_TEXT(5, trace, "txbuffcb");
15121512
/* Put buffer back to pool. */
15131513
lcs_release_buffer(channel, buffer);
1514-
card = (struct lcs_card *)
1515-
((char *) channel - offsetof(struct lcs_card, write));
1514+
card = container_of(channel, struct lcs_card, write);
15161515
if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev))
15171516
netif_wake_queue(card->dev);
15181517
spin_lock(&card->lock);
@@ -1810,8 +1809,7 @@ lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
18101809
LCS_DBF_TEXT(4, trace, "-eiogpkt");
18111810
return;
18121811
}
1813-
card = (struct lcs_card *)
1814-
((char *) channel - offsetof(struct lcs_card, read));
1812+
card = container_of(channel, struct lcs_card, read);
18151813
offset = 0;
18161814
while (lcs_hdr->offset != 0) {
18171815
if (lcs_hdr->offset <= 0 ||

‎drivers/video/sa1100fb.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ struct sa1100fb_info {
110110
#endif
111111
};
112112

113-
#define __type_entry(ptr,type,member) ((type *)((char *)(ptr)-offsetof(type,member)))
114-
115-
#define TO_INF(ptr,member) __type_entry(ptr,struct sa1100fb_info,member)
113+
#define TO_INF(ptr,member) container_of(ptr,struct sa1100fb_info,member)
116114

117115
#define SA1100_PALETTE_MODE_VAL(bpp) (((bpp) & 0x018) << 9)
118116

‎include/linux/security.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ struct request_sock;
492492
* Note that the fown_struct, @fown, is never outside the context of a
493493
* struct file, so the file structure (and associated security information)
494494
* can always be obtained:
495-
* (struct file *)((long)fown - offsetof(struct file,f_owner));
495+
* container_of(fown, struct file, f_owner)
496496
* @tsk contains the structure of task receiving signal.
497497
* @fown contains the file owner information.
498498
* @sig is the signal that will be sent. When 0, kernel sends SIGIO.

‎security/selinux/hooks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ static int selinux_file_send_sigiotask(struct task_struct *tsk,
26542654
struct file_security_struct *fsec;
26552655

26562656
/* struct fown_struct is never outside the context of a struct file */
2657-
file = (struct file *)((long)fown - offsetof(struct file,f_owner));
2657+
file = container_of(fown, struct file, f_owner);
26582658

26592659
tsec = tsk->security;
26602660
fsec = file->f_security;

0 commit comments

Comments
 (0)