Skip to content

Commit f92ceb0

Browse files
keesdavem330
authored andcommitted
DECnet: Use container_of() for embedded struct
Instead of a direct cross-type cast, use conatiner_of() to locate the embedded structure, even in the face of future struct layout randomization. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 32f1bc0 commit f92ceb0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/decnet/dn_neigh.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct neigh_table dn_neigh_table = {
110110
static int dn_neigh_construct(struct neighbour *neigh)
111111
{
112112
struct net_device *dev = neigh->dev;
113-
struct dn_neigh *dn = (struct dn_neigh *)neigh;
113+
struct dn_neigh *dn = container_of(neigh, struct dn_neigh, n);
114114
struct dn_dev *dn_db;
115115
struct neigh_parms *parms;
116116

@@ -339,7 +339,7 @@ int dn_to_neigh_output(struct net *net, struct sock *sk, struct sk_buff *skb)
339339
struct dst_entry *dst = skb_dst(skb);
340340
struct dn_route *rt = (struct dn_route *) dst;
341341
struct neighbour *neigh = rt->n;
342-
struct dn_neigh *dn = (struct dn_neigh *)neigh;
342+
struct dn_neigh *dn = container_of(neigh, struct dn_neigh, n);
343343
struct dn_dev *dn_db;
344344
bool use_long;
345345

@@ -391,7 +391,7 @@ int dn_neigh_router_hello(struct net *net, struct sock *sk, struct sk_buff *skb)
391391

392392
neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
393393

394-
dn = (struct dn_neigh *)neigh;
394+
dn = container_of(neigh, struct dn_neigh, n);
395395

396396
if (neigh) {
397397
write_lock(&neigh->lock);
@@ -451,7 +451,7 @@ int dn_neigh_endnode_hello(struct net *net, struct sock *sk, struct sk_buff *skb
451451

452452
neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
453453

454-
dn = (struct dn_neigh *)neigh;
454+
dn = container_of(neigh, struct dn_neigh, n);
455455

456456
if (neigh) {
457457
write_lock(&neigh->lock);
@@ -510,7 +510,7 @@ static void neigh_elist_cb(struct neighbour *neigh, void *_info)
510510
if (neigh->dev != s->dev)
511511
return;
512512

513-
dn = (struct dn_neigh *) neigh;
513+
dn = container_of(neigh, struct dn_neigh, n);
514514
if (!(dn->flags & (DN_NDFLAG_R1|DN_NDFLAG_R2)))
515515
return;
516516

@@ -549,7 +549,7 @@ int dn_neigh_elist(struct net_device *dev, unsigned char *ptr, int n)
549549
static inline void dn_neigh_format_entry(struct seq_file *seq,
550550
struct neighbour *n)
551551
{
552-
struct dn_neigh *dn = (struct dn_neigh *) n;
552+
struct dn_neigh *dn = container_of(n, struct dn_neigh, n);
553553
char buf[DN_ASCBUF_LEN];
554554

555555
read_lock(&n->lock);

0 commit comments

Comments
 (0)