Skip to contentSkip to conversation

drop unneeded goto

PATCH Applied Julia Lawall 5 participants 14 messages May 28, 2015 – Jun 8, 2015

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

cover drop unneeded goto

These patches drop gotos that jump to a label that is at the next instruction, in the case that the label is not used elsewhere in the function. The complete semantic patch that performs this transformation is as follows:

// <smpl>
@r@
position p;
identifier l;
@@

if (...) goto l@p;
l:

@script:ocaml s@
p << r.p;
nm;
@@

nm := (List.hd p).current_element

@ok exists@
identifier s.nm,l;
position p != r.p;
@@

nm(...) {
<+... goto l@p; ...+>
}

@depends on !ok@
identifier s.nm;
position r.p;
identifier l;
@@

nm(...) {
<...
- if(...) goto l@p; l:
...>
}
// </smpl>

#1 lore raw

PATCH 1/9 drivers/media/usb/airspy/airspy.c: drop unneeded goto

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/media/usb/airspy/airspy.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/media/usb/airspy/airspy.c +0 -3
index 4069234..8f2e1c2 100644
@@ -937,9 +937,6 @@ static int airspy_set_if_gain(struct airspy *s)
 	ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val,
 			&u8tmp, 1);
 	if (ret)
-		goto err;
-err:
-	if (ret)
 		dev_dbg(s->dev, "failed=%d\n", ret);
 
 	return ret;
#2 lore raw

Re: [PATCH 1/9] drivers/media/usb/airspy/airspy.c: drop unneeded goto

Quoted 4 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

Seems sensible but:

drivers/media/usb/airspy/airspy.c

Quoted 1 line
drivers/media/usb/airspy/airspy.c +0 -0

[]

drivers/media/usb/airspy/airspy.c static int airspy_set_if_gain(struct airspy *s) · line 942

Quoted 10 lines
drivers/media/usb/airspy/airspy.c +0 -3
@@ -937,9 +937,6 @@ static int airspy_set_if_gain(struct airspy *s)
 	ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val,
 			&u8tmp, 1);
 	if (ret)
-		goto err;
-err:
-	if (ret)
 		dev_dbg(s->dev, "failed=%d\n", ret);
 
 	return ret;

Ideally the function above this should also be modified do drop the unnecessary double test of ret

static int airspy_set_mixer_gain(struct airspy *s)

{
	int ret;
	u8 u8tmp;

	dev_dbg(s->dev, "mixer auto=%d->%d val=%d->%d\n",
			s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val,
			s->mixer_gain->cur.val, s->mixer_gain->val);

	ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val,
			&u8tmp, 1);
	if (ret)
		goto err;

	if (s->mixer_gain_auto->val = false) {
		ret = airspy_ctrl_msg(s, CMD_SET_MIXER_GAIN, 0,
				s->mixer_gain->val, &u8tmp, 1);
		if (ret)
			goto err;
	}
err:
	if (ret)
		dev_dbg(s->dev, "failed=%d\n", ret);

	return ret;
}

These could become something like:

static int airspy_set_mixer_gain(struct airspy *s)

{
	int ret;
	u8 u8tmp;

	dev_dbg(s->dev, "mixer auto=%d->%d val=%d->%d\n",
			s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val,
			s->mixer_gain->cur.val, s->mixer_gain->val);

	ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val,
			&u8tmp, 1);
	if (ret)
		goto err;

	if (s->mixer_gain_auto->val = false) {
		ret = airspy_ctrl_msg(s, CMD_SET_MIXER_GAIN, 0,
				s->mixer_gain->val, &u8tmp, 1);
		if (ret)
			goto err;
	}

	return 0;

err:

	dev_dbg(s->dev, "failed=%d\n", ret);
	return ret;
}
#3 lore raw

PATCH 2/9 ipv6: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

Also remove the unnecessary ret variable.

---
 net/ipv6/raw.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
net/ipv6/raw.c +1 -7
index 484a5c1..ca4700c 100644
@@ -1327,13 +1327,7 @@ static struct inet_protosw rawv6_protosw = {
 
 int __init rawv6_init(void)
 {
-	int ret;
-
-	ret = inet6_register_protosw(&rawv6_protosw);
-	if (ret)
-		goto out;
-out:
-	return ret;
+	return inet6_register_protosw(&rawv6_protosw);
 }
 
 void rawv6_exit(void)
maintainer Applied
#4 lore raw

Re: [PATCH 2/9] ipv6: drop unneeded goto

From: Julia Lawall <[email protected]>
Date: Thu, 28 May 2015 23:02:17 +0200

Quoted 7 lines

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

...

Quoted 3 lines

Also remove the unnecessary ret variable.

Applied, thanks Julia.

#5 lore raw

PATCH 3/9 NFS: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

Also drop the unnecessary ret variable.

---
 fs/nfs/nfs4idmap.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs4idmap.c +1 -6
index 2e1737c..535dfc6 100644
@@ -494,12 +494,7 @@ nfs_idmap_delete(struct nfs_client *clp)
 
 int nfs_idmap_init(void)
 {
-	int ret;
-	ret = nfs_idmap_init_keyring();
-	if (ret != 0)
-		goto out;
-out:
-	return ret;
+	return nfs_idmap_init_keyring();
 }
 
 void nfs_idmap_quit(void)
#6 lore raw

PATCH 4/9 RDMA/ocrdma: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/infiniband/hw/ocrdma/ocrdma_hw.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +3 -12
index 47615ff..0f3b5ea 100644
@@ -1884,9 +1884,7 @@ int ocrdma_mbx_dealloc_lkey(struct ocrdma_dev *dev, int fr_mr, u32 lkey)
 	cmd->lkey = lkey;
 	cmd->rsvd_frmr = fr_mr ? 1 : 0;
 	status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
-	if (status)
-		goto mbx_err;
-mbx_err:
+
 	kfree(cmd);
 	return status;
 }
@@ -1965,9 +1963,7 @@ static int ocrdma_mbx_reg_mr_cont(struct ocrdma_dev *dev,
 		    upper_32_bits(hwmr->pbl_table[i + pbl_offset].pa);
 	}
 	status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
-	if (status)
-		goto mbx_err;
-mbx_err:
+
 	kfree(cmd);
 	return status;
 }
@@ -2648,10 +2644,7 @@ int ocrdma_mbx_destroy_qp(struct ocrdma_dev *dev, struct ocrdma_qp *qp)
 		return status;
 	cmd->qp_id = qp->id;
 	status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
-	if (status)
-		goto mbx_err;
 
-mbx_err:
 	kfree(cmd);
 	if (qp->sq.va)
 		dma_free_coherent(&pdev->dev, qp->sq.len, qp->sq.va, qp->sq.pa);
@@ -3061,9 +3054,7 @@ static int ocrdma_mbx_modify_eqd(struct ocrdma_dev *dev, struct ocrdma_eq *eq,
 				(eq[i].aic_obj.prev_eqd * 65)/100;
 	}
 	status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
-	if (status)
-		goto mbx_err;
-mbx_err:
+
 	kfree(cmd);
 	return status;
 }
#7 lore raw

PATCH 5/9 wl1251: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/net/wireless/ti/wl1251/acx.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/net/wireless/ti/wl1251/acx.c +0 -3
index 5695628..d6fbdda 100644
@@ -53,10 +53,7 @@ int wl1251_acx_station_id(struct wl1251 *wl)
 		mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
 
 	ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
-	if (ret < 0)
-		goto out;
 
-out:
 	kfree(mac);
 	return ret;
 }
Applied
#8 lore raw

Re: [5/9] wl1251: drop unneeded goto

Quoted 18 lines

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

(quoted diff) +0 -2
-if (...) goto l;
-l:

// </smpl>

Quoted 1 line

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#9 lore raw

PATCH 6/9 ssb: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

Also drop the unneeded err variable.

---
 drivers/ssb/pci.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/ssb/pci.c +1 -7
index 0f28c08..d6ca4d3 100644
@@ -1173,17 +1173,11 @@ void ssb_pci_exit(struct ssb_bus *bus)
 int ssb_pci_init(struct ssb_bus *bus)
 {
 	struct pci_dev *pdev;
-	int err;
 
 	if (bus->bustype != SSB_BUSTYPE_PCI)
 		return 0;
 
 	pdev = bus->host_pci;
 	mutex_init(&bus->sprom_mutex);
-	err = device_create_file(&pdev->dev, &dev_attr_ssb_sprom);
-	if (err)
-		goto out;
-
-out:
-	return err;
+	return device_create_file(&pdev->dev, &dev_attr_ssb_sprom);
 }
#10 lore raw

PATCH 7/9 drivers/media/tuners/e4000.c: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/media/tuners/e4000.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/media/tuners/e4000.c +0 -3
index 510239f..50c0f0d 100644
@@ -103,9 +103,6 @@ static int e4000_sleep(struct dvb_frontend *fe)
 
 	ret = regmap_write(s->regmap, 0x00, 0x00);
 	if (ret)
-		goto err;
-err:
-	if (ret)
 		dev_dbg(&s->client->dev, "failed=%d\n", ret);
 
 	return ret;
#11 lore raw

PATCH 8/9 staging/lustre/mdc: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/staging/lustre/lustre/mdc/mdc_request.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/staging/lustre/lustre/mdc/mdc_request.c +0 -3
index cbbdfce..0f120f2 100644
@@ -1818,10 +1818,7 @@ static int mdc_ioc_swap_layouts(struct obd_export *exp,
 	ptlrpc_request_set_replen(req);
 
 	rc = ptlrpc_queue_wait(req);
-	if (rc)
-		goto out;
 
-out:
 	ptlrpc_req_finished(req);
 	return rc;
 }
#12 lore raw

PATCH 9/9 regmap: drop unneeded goto

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier l;
@@

-if (...) goto l;
-l:
// </smpl>

---
 drivers/base/regmap/regmap.c |    3 ---
 1 file changed, 3 deletions(-)
drivers/base/regmap/regmap.c +0 -3
index e5eef6f..3378a11 100644
@@ -2583,10 +2583,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 	map->async = true;
 
 	ret = _regmap_multi_reg_write(map, regs, num_regs);
-	if (ret != 0)
-		goto out;
 
-out:
 	map->async = false;
 	map->cache_bypass = bypass;
 
maintainer Applied
#13 lore raw

Re: [PATCH 9/9] regmap: drop unneeded goto

Quoted 4 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Delete jump to a label on the next line, when that label is not used elsewhere.

Applied, thanks.