Skip to contentSkip to conversation

caif: cleanup: remove duplicate checks

PATCH Superseded Dan Carpenter 4 participants 5 messages May 22, 2010 – May 31, 2010

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

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
index df43f26..cc2f072 100644
@@ -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;
 
#1 lore raw
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.

net/caif/cfcnfg.c +0 -2
index df43f26..cc2f072 100644
@@ -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

#2 lore raw

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
index df43f26..7c81974 100644
@@ -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;
 
Acked-by Sjur Braendeland on v2 1/1
#3 lore raw
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.

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

maintainer Applied
#4 lore raw

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.

Thanks, this looks good.

Applied.