caif: cleanup: remove duplicate checks
Subsystems (3)
PATCH 1/1 caif: cleanup: remove duplicate checks
These checks merely duplicate the things we've asserted already. In the case of the checks for null we've already dereferenced those variables as well.
net/caif/cfcnfg.c +1 -5
@@ -313,14 +313,10 @@ cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv,caif_assert (phyinfo->phy_layer !=NULL );caif_assert (phyinfo->phy_layer->id = phyid); -if (phyinfo !=NULL && - phyinfo->phy_ref_count++ = 0 && - phyinfo->phy_layer !=NULL && + if (phyinfo->phy_ref_count++ = 0 && phyinfo->phy_layer->modemcmd !=NULL ) { -caif_assert (phyinfo->phy_layer->id = phyid); phyinfo->phy_layer->modemcmd (phyinfo->phy_layer, _CAIF_MODEMCMD_PHYIF_USEFULL); - } adapt_layer->id = channel_id;
Quoted 16 lines · Dan Carpenter
These checks merely duplicate the things we've asserted already. In the case of the checks for null we've already dereferenced those variables as well.
Signed-off-by Dan Carpenter <[email protected]>net/caif/cfcnfg.c +0
-2@@ -313,14 +313,10 @@ cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv,caif_assert (phyinfo->phy_layer !=NULL );caif_assert (phyinfo->phy_layer->id = phyid); - if (phyinfo != NULL && - phyinfo->phy_ref_count++ = 0 &&
net/caif/cfcnfg.c cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv, · line 322
Quoted 10 lines
net/caif/cfcnfg.c +1
-3- phyinfo->phy_layer != NULL && + if (phyinfo->phy_ref_count++ = 0 && phyinfo->phy_layer->modemcmd !=NULL ) { -caif_assert (phyinfo->phy_layer->id = phyid); phyinfo->phy_layer->modemcmd (phyinfo->phy_layer, _CAIF_MODEMCMD_PHYIF_USEFULL); - } adapt_layer->id = channel_id;
hi Dan,
the phyinfo->phy_ref_count++ is very hidden, perhaps in terms of readability it is better to move the phyinfo->phy_ref_count++ inside.
just my 2 cents,
re,
wh
PATCH v2 1/1 caif: cleanup: remove duplicate checks
"phyinfo" can never be null here because we assigned it an address, so I removed both the assert and the second check inside the if statement. I removed the "phyinfo->phy_layer != NULL" check as well because that was asserted earlier.
Walter Harms suggested I move the "phyinfo->phy_ref_count++;" outside the if condition for readability, so I have done that.
---
The original code increments phyinfo->phy_ref_count++ even if phyinfo->phy_layer->modemcmd is NULL. I kept it the same in my code, but maybe I should change that?
v2: Removed an assert. Moved the increment outside the if condition.
net/caif/cfcnfg.c +2 -6
@@ -308,19 +308,15 @@ cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv,caif_assert (cnfg !=NULL );caif_assert (phyid !=0 ); phyinfo = &cnfg->phy_layers[phyid]; -caif_assert (phyinfo !=NULL );caif_assert (phyinfo->id = phyid);caif_assert (phyinfo->phy_layer !=NULL );caif_assert (phyinfo->phy_layer->id = phyid); -if (phyinfo !=NULL && - phyinfo->phy_ref_count++ = 0 && - phyinfo->phy_layer !=NULL && + phyinfo->phy_ref_count++; +if (phyinfo->phy_ref_count =1 && phyinfo->phy_layer->modemcmd !=NULL ) { -caif_assert (phyinfo->phy_layer->id = phyid); phyinfo->phy_layer->modemcmd (phyinfo->phy_layer, _CAIF_MODEMCMD_PHYIF_USEFULL); - } adapt_layer->id = channel_id;
Quoted 9 lines · Dan Carpenter
"phyinfo" can never be null here because we assigned it an address, so I removed both the assert and the second check inside the if statement. Â I removed the "
phyinfo->phy_layer!= NULL" check as well because that was asserted earlier.Walter Harms suggested I move the "phyinfo->phy_ref_count++;" outside the if condition for readability, so I have done that.
Signed-off-by Dan Carpenter <[email protected]>
Thanks, this looks good.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Sjur Brændeland <[email protected]>
Date: Mon, 24 May 2010 22:47:41 +0200
Quoted 6 lines
Quoted 5 lines · Dan Carpenter
"phyinfo" can never be null here because we assigned it an address, so I removed both the assert and the second check inside the if statement. I removed the "
phyinfo->phy_layer!= NULL" check as well because that was asserted earlier.
Quoted 6 lines
Quoted 4 lines
Walter Harms suggested I move the "phyinfo->phy_ref_count++;" outside the if condition for readability, so I have done that.
Signed-off-by Dan Carpenter <[email protected]>Acked-by Sjur Braendeland <[email protected]>Thanks, this looks good.
Applied.