Skip to contentSkip to conversation

net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb

PATCH In review Gustavo A. R. Silva 1 participant 4 messages Oct 30, 2017 – Oct 31, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: caif: chnl_net: remove unnecessary null check in chnl_recv_cb

container_of is never null, so this null check is unnecessary.

This code was detected with the help of Coccinelle.

---
 net/caif/chnl_net.c | 2 --
 1 file changed, 2 deletions(-)
net/caif/chnl_net.c +0 -2
index 922ac1d..489298d 100644
@@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
 	u8 buf;
 
 	priv = container_of(layr, struct chnl_net, chnl);
-	if (!priv)
-		return -EINVAL;
 
 	skb = (struct sk_buff *) cfpkt_tonative(pkt);
 
Signature · 1 line
2.7.4
#1 lore raw

Hi,

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 24 lines

container_of is never null, so this null check is unnecessary.

This code was detected with the help of Coccinelle.

---
 net/caif/chnl_net.c | 2 --
 1 file changed, 2 deletions(-)
net/caif/chnl_net.c +0 -3
index 922ac1d..489298d 100644
@@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,  
 struct cfpkt *pkt)
 	u8 buf;
 
 	priv = container_of(layr, struct chnl_net, chnl);
-	if (!priv)
-		return -EINVAL;
 
 	skb = (struct sk_buff *) cfpkt_tonative(pkt);
 
--
Quoted 1 line

2.7.4

Please, ignore this patch.

I just realized that function chnl_recv_cb is being called only during initialization:

chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() -> chnl_recv_cb():

static void ipcaif_net_setup(struct net_device *dev) {
[...]

	priv = netdev_priv(dev);
	priv->chnl.receive = chnl_recv_cb;

[...]
}

static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
.kind = "caif",
.priv_size = sizeof(struct chnl_net),
.setup = ipcaif_net_setup,
.maxtype = IFLA_CAIF_MAX,
.policy = ipcaif_policy,
.newlink = ipcaif_newlink,
.changelink = ipcaif_changelink,
.get_size = ipcaif_get_size,
.fill_info = ipcaif_fill_info,

};

static int __init chnl_init_module(void)

{
	return rtnl_link_register(&ipcaif_link_ops);
}

Thanks
--
Gustavo A. R. Silva

#2 lore raw

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 27 lines

Hi,

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 23 lines

container_of is never null, so this null check is unnecessary.

This code was detected with the help of Coccinelle.

---
net/caif/chnl_net.c | 2 --

1 file changed, 2 deletions(-)
net/caif/chnl_net.c +0 -2
index 922ac1d..489298d 100644
@@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,  
 struct cfpkt *pkt)
 	u8 buf;
 
 	priv = container_of(layr, struct chnl_net, chnl);
-	if (!priv)
-		return -EINVAL;
 
 	skb = (struct sk_buff *) cfpkt_tonative(pkt);
Quoted 9 lines
Quoted 2 lines

--
2.7.4

Please, ignore this patch.

I just realized that function chnl_recv_cb is being called only during initialization:

chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() -> chnl_recv_cb():

Well, here ipcaif_net_setup stores a pointer to chnl_recv_cb in a structure. It doesn't call it.

Quoted 20 lines

static void ipcaif_net_setup(struct net_device *dev) {
[...]

	priv = netdev_priv(dev);
	priv->chnl.receive = chnl_recv_cb;

[...]
}

static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
.kind = "caif",
.priv_size = sizeof(struct chnl_net),
.setup = ipcaif_net_setup,
.maxtype = IFLA_CAIF_MAX,
.policy = ipcaif_policy,
.newlink = ipcaif_newlink,
.changelink = ipcaif_changelink,
.get_size = ipcaif_get_size,
.fill_info = ipcaif_fill_info,

Quoted 7 lines

};

static int __init chnl_init_module(void)

{
	return rtnl_link_register(&ipcaif_link_ops);
}

--
Gustavo A. R. Silva

#3 lore raw

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 23 lines

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 21 lines

Hi,

Quoting "Gustavo A. R. Silva" <[email protected]>:

Quoted 17 lines

container_of is never null, so this null check is unnecessary.

This code was detected with the help of Coccinelle.

---
net/caif/chnl_net.c | 2 --

1 file changed, 2 deletions(-)
net/caif/chnl_net.c +0 -0
index 922ac1d..489298d 100644
@@ -77,8 +77,6 @@ static int chnl_recv_cb(struct cflayer *layr,  
 struct cfpkt *pkt)
 	u8 buf;
 
Quoted 3 lines
Quoted 3 lines

net/caif/chnl_net.c static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt) · line 81

Quoted 3 lines
net/caif/chnl_net.c +0 -2
 	priv = container_of(layr, struct chnl_net, chnl);
-	if (!priv)
-		return -EINVAL;

But the driver only passes in to container_of the type of driver structure registered with it. So this type of manipulation must be completely safe. Right?

Now it seems to me (again) that the patch is fine.

I'm sorry, I'm a little bit confused here.

Quoted 43 lines
Quoted 12 lines
Quoted 5 lines
net/caif/chnl_net.c +0 -1
 	skb = (struct sk_buff *) cfpkt_tonative(pkt);
 
--

2.7.4

Please, ignore this patch.

I just realized that function chnl_recv_cb is being called only during initialization:

chnl_init_module() -> rtnl_link_register() -> ipcaif_net_setup() -> chnl_recv_cb():

Well, here ipcaif_net_setup stores a pointer to chnl_recv_cb in a structure. It doesn't call it.

Quoted 27 lines

static void ipcaif_net_setup(struct net_device *dev) {
[...]

	priv = netdev_priv(dev);
	priv->chnl.receive = chnl_recv_cb;

[...]
}

static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
.kind = "caif",
.priv_size = sizeof(struct chnl_net),
.setup = ipcaif_net_setup,
.maxtype = IFLA_CAIF_MAX,
.policy = ipcaif_policy,
.newlink = ipcaif_newlink,
.changelink = ipcaif_changelink,
.get_size = ipcaif_get_size,
.fill_info = ipcaif_fill_info,

};

static int __init chnl_init_module(void)

{
	return rtnl_link_register(&ipcaif_link_ops);
}