Skip to contentSkip to conversation

Bluetooth/btmrvl_sdio: Adjustments for three function implementations

PATCH In review SF Markus Elfring 2 participants 13 messages Mar 12, 2018 – Mar 13, 2018

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

cover Bluetooth/btmrvl_sdio: Adjustments for three function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 12:10:24 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Use common error handling code in btmrvl_sdio_register_dev() Delete an unnecessary variable initialisation in btmrvl_sdio_register_dev() One check less in btmrvl_sdio_card_to_host() after error detection Delete an unnecessary variable initialisation in btmrvl_sdio_card_to_host() Use common error handling code in btmrvl_sdio_download_fw_w_helper()

 drivers/bluetooth/btmrvl_sdio.c | 102 ++++++++++++++++++----------------------
 1 file changed, 46 insertions(+), 56 deletions(-)
Signature · 1 line
2.16.2
#1 lore raw

PATCH 1/5 Bluetooth: btmrvl: Use common error handling code in btmrvl_sdio_register_dev()

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 10:15:17 +0100

Adjust a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/bluetooth/btmrvl_sdio.c | 50 ++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 31 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +19 -31
index 0f020254fd39..df2a04bd8428 100644
@@ -949,31 +949,24 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 	ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE);
 	if (ret) {
 		BT_ERR("cannot set SDIO block size");
-		ret = -EIO;
-		goto release_irq;
+		goto release_with_eio;
 	}
 
 	reg = sdio_readb(func, card->reg->io_port_0, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport = reg;
 
 	reg = sdio_readb(func, card->reg->io_port_1, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport |= (reg << 8);
 
 	reg = sdio_readb(func, card->reg->io_port_2, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport |= (reg << 16);
 
@@ -981,26 +974,20 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 
 	if (card->reg->int_read_to_clear) {
 		reg = sdio_readb(func, card->reg->host_int_rsr, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
+
 		sdio_writeb(func, reg | 0x3f, card->reg->host_int_rsr, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
 
 		reg = sdio_readb(func, card->reg->card_misc_cfg, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
+
 		sdio_writeb(func, reg | 0x10, card->reg->card_misc_cfg, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
 	}
 
 	sdio_set_drvdata(func, card);
@@ -1009,7 +996,8 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 
 	return 0;
 
-release_irq:
+release_with_eio:
+	ret = -EIO;
 	sdio_release_irq(func);
 
 disable_func:
Signature · 1 line
2.16.2
maintainer
#2 lore raw

Re: [PATCH 1/5] Bluetooth: btmrvl: Use common error handling code in btmrvl_sdio_register_dev()

Hi Markus,

Quoted 99 lines

Adjust a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
drivers/bluetooth/btmrvl_sdio.c | 50 ++++++++++++++++-------------------------

1 file changed, 19 insertions(+), 31 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +19 -31
index 0f020254fd39..df2a04bd8428 100644
@@ -949,31 +949,24 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 	ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE);
 	if (ret) {
 		BT_ERR("cannot set SDIO block size");
-		ret = -EIO;
-		goto release_irq;
+		goto release_with_eio;
 	}
 
 	reg = sdio_readb(func, card->reg->io_port_0, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport = reg;
 
 	reg = sdio_readb(func, card->reg->io_port_1, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport |= (reg << 8);
 
 	reg = sdio_readb(func, card->reg->io_port_2, &ret);
-	if (ret < 0) {
-		ret = -EIO;
-		goto release_irq;
-	}
+	if (ret < 0)
+		goto release_with_eio;
 
 	card->ioport |= (reg << 16);
 
@@ -981,26 +974,20 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 
 	if (card->reg->int_read_to_clear) {
 		reg = sdio_readb(func, card->reg->host_int_rsr, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
+
 		sdio_writeb(func, reg | 0x3f, card->reg->host_int_rsr, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
 
 		reg = sdio_readb(func, card->reg->card_misc_cfg, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
+
 		sdio_writeb(func, reg | 0x10, card->reg->card_misc_cfg, &ret);
-		if (ret < 0) {
-			ret = -EIO;
-			goto release_irq;
-		}
+		if (ret < 0)
+			goto release_with_eio;
 	}
 
 	sdio_set_drvdata(func, card);
@@ -1009,7 +996,8 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 
 	return 0;
 
-release_irq:
+release_with_eio:
+	ret = -EIO;
 	sdio_release_irq(func);
 
Quoted 1 line

disable_func:

please do not send me any patches with renaming goto labels. I dislike long goto labels anyway and it doesn’t make it any better in mind.

In addition, this patch is half baked. If you want to do something, then you replace all err = -EIO and use this.

release_irq:

        sdio_release_irq(func);

disable_func:

        sdio_disable_func(func);

release_host:

        sdio_release_host(func);

	return -EIO;

And replace goto failed with return -EINVAL;

Regards

Marcel

--
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

#3 lore raw

PATCH 2/5 Bluetooth: btmrvl: Delete an unnecessary variable initialisation in btmrvl_sdio_register_dev()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 10:20:04 +0100

The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/bluetooth/btmrvl_sdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btmrvl_sdio.c +1 -1
index df2a04bd8428..84c222abf0f7 100644
@@ -920,7 +920,7 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
 {
 	struct sdio_func *func;
 	u8 reg;
-	int ret = 0;
+	int ret;
 
 	if (!card || !card->func) {
 		BT_ERR("Error: card or function is NULL!");
Signature · 1 line
2.16.2
maintainer
#4 lore raw

Re: [PATCH 2/5] Bluetooth: btmrvl: Delete an unnecessary variable initialisation in btmrvl_sdio_register_dev()

Hi Markus,

Quoted 7 lines

The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
drivers/bluetooth/btmrvl_sdio.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#5 lore raw

PATCH 3/5 Bluetooth: btmrvl: One check less in btmrvl_sdio_card_to_host() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 11:13:00 +0100

One check could be repeated by the btmrvl_sdio_card_to_host() function during error handling even if the relevant properties can be determined for the involved variables before by source code analysis.

* Adjust jump targets so that an extra check can be omitted at the end.

* Reuse a bit of exception handling better.

* Delete an initialisation for the local variable "skb" which became unnecessary with this refactoring.

---
 drivers/bluetooth/btmrvl_sdio.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +18 -17
index 84c222abf0f7..9854addc8e96 100644
@@ -687,5 +687,5 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 {
 	u16 buf_len = 0;
 	int ret, num_blocks, blksz;
-	struct sk_buff *skb = NULL;
+	struct sk_buff *skb;
 	u32 type;
@@ -695,16 +695,14 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 
 	if (!card || !card->func) {
 		BT_ERR("card or function is NULL!");
-		ret = -EINVAL;
-		goto exit;
+		goto e_inval;
 	}
 
 	/* Read the length of data to be transferred */
 	ret = btmrvl_sdio_read_rx_len(card, &buf_len);
 	if (ret < 0) {
 		BT_ERR("read rx_len failed");
-		ret = -EIO;
-		goto exit;
+		goto e_io;
 	}
 
 	blksz = SDIO_BLOCK_SIZE;
@@ -713,8 +711,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (buf_len <= SDIO_HEADER_LEN
 	    || (num_blocks * blksz) > ALLOC_BUF_SIZE) {
 		BT_ERR("invalid packet length: %d", buf_len);
-		ret = -EINVAL;
-		goto exit;
+		goto e_inval;
 	}
 
 	/* Allocate buffer */
@@ -722,7 +719,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (!skb) {
 		BT_ERR("No free skb");
 		ret = -ENOMEM;
-		goto exit;
+		goto increment_counter;
 	}
 
 	if ((unsigned long) skb->data & (BTSDIO_DMA_ALIGN - 1)) {
@@ -738,8 +735,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 			  num_blocks * blksz);
 	if (ret < 0) {
 		BT_ERR("readsb failed: %d", ret);
-		ret = -EIO;
-		goto exit;
+		goto free_skb;
 	}
 
 	/* This is SDIO specific header length: byte[2][1][0], type: byte[3]
@@ -753,8 +749,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (buf_len > blksz * num_blocks) {
 		BT_ERR("Skip incorrect packet: hdrlen %d buffer %d",
 		       buf_len, blksz * num_blocks);
-		ret = -EIO;
-		goto exit;
+		goto free_skb;
 	}
 
 	type = payload[3];
@@ -797,12 +792,18 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 		break;
 	}
 
-exit:
-	if (ret) {
-		hdev->stat.err_rx++;
-		kfree_skb(skb);
-	}
+	return 0;
+
+free_skb:
+	kfree_skb(skb);
+e_io:
+	ret = -EIO;
+	goto increment_counter;
 
+e_inval:
+	ret = -EINVAL;
+increment_counter:
+	hdev->stat.err_rx++;
 	return ret;
 }
 
Signature · 1 line
2.16.2
maintainer
#6 lore raw

Re: [PATCH 3/5] Bluetooth: btmrvl: One check less in btmrvl_sdio_card_to_host() after error detection

Hi Markus,

Quoted 97 lines

One check could be repeated by the btmrvl_sdio_card_to_host() function during error handling even if the relevant properties can be determined for the involved variables before by source code analysis.

* Adjust jump targets so that an extra check can be omitted at the end.

* Reuse a bit of exception handling better.

* Delete an initialisation for the local variable "skb" which became unnecessary with this refactoring.

---
drivers/bluetooth/btmrvl_sdio.c | 35 ++++++++++++++++++-----------------

1 file changed, 18 insertions(+), 17 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +10 -17
index 84c222abf0f7..9854addc8e96 100644
@@ -687,5 +687,5 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 {
 	u16 buf_len = 0;
 	int ret, num_blocks, blksz;
-	struct sk_buff *skb = NULL;
+	struct sk_buff *skb;
 	u32 type;
@@ -695,16 +695,14 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 
 	if (!card || !card->func) {
 		BT_ERR("card or function is NULL!");
-		ret = -EINVAL;
-		goto exit;
+		goto e_inval;
 	}
 
 	/* Read the length of data to be transferred */
 	ret = btmrvl_sdio_read_rx_len(card, &buf_len);
 	if (ret < 0) {
 		BT_ERR("read rx_len failed");
-		ret = -EIO;
-		goto exit;
+		goto e_io;
 	}
 
 	blksz = SDIO_BLOCK_SIZE;
@@ -713,8 +711,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (buf_len <= SDIO_HEADER_LEN
 	    || (num_blocks * blksz) > ALLOC_BUF_SIZE) {
 		BT_ERR("invalid packet length: %d", buf_len);
-		ret = -EINVAL;
-		goto exit;
+		goto e_inval;
 	}
 
 	/* Allocate buffer */
@@ -722,7 +719,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (!skb) {
 		BT_ERR("No free skb");
 		ret = -ENOMEM;
-		goto exit;
+		goto increment_counter;
 	}
 
 	if ((unsigned long) skb->data & (BTSDIO_DMA_ALIGN - 1)) {
@@ -738,8 +735,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 			  num_blocks * blksz);
 	if (ret < 0) {
 		BT_ERR("readsb failed: %d", ret);
-		ret = -EIO;
-		goto exit;
+		goto free_skb;
 	}
 
 	/* This is SDIO specific header length: byte[2][1][0], type: byte[3]
@@ -753,8 +749,7 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	if (buf_len > blksz * num_blocks) {
 		BT_ERR("Skip incorrect packet: hdrlen %d buffer %d",
 		       buf_len, blksz * num_blocks);
-		ret = -EIO;
-		goto exit;
+		goto free_skb;
 	}
 
 	type = payload[3];
@@ -797,12 +792,18 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 		break;
 	}
 
-exit:
-	if (ret) {
-		hdev->stat.err_rx++;
-		kfree_skb(skb);
-	}
+	return 0;
+
+free_skb:

drivers/bluetooth/btmrvl_sdio.c static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv) · line 807

Quoted 10 lines
drivers/bluetooth/btmrvl_sdio.c +8 -0
+	kfree_skb(skb);
+e_io:
+	ret = -EIO;
+	goto increment_counter;
 
+e_inval:
+	ret = -EINVAL;
+increment_counter:
+	hdev->stat.err_rx++;
 	return ret;

Nope!

This is not easier to read for me. This goto exit jumping and I hate that. Actually to be honest this kind of goto jumping makes my brain hurt and I want to avoid it.

Regards

Marcel

#7 lore raw

Re: [3/5] Bluetooth: btmrvl: One check less in btmrvl_sdio_card_to_host()

Quoted 25 lines
Quoted 12 lines
drivers/bluetooth/btmrvl_sdio.c +3 -5
@@ -797,12 +792,18 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 		break;
 	}
 
-exit:
-	if (ret) {
-		hdev->stat.err_rx++;
-		kfree_skb(skb);
-	}
+	return 0;
+
+free_skb:

drivers/bluetooth/btmrvl_sdio.c static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv) · line 807

Quoted 10 lines
drivers/bluetooth/btmrvl_sdio.c +8 -0
+	kfree_skb(skb);
+e_io:
+	ret = -EIO;
+	goto increment_counter;
 
+e_inval:
+	ret = -EINVAL;
+increment_counter:
+	hdev->stat.err_rx++;
 	return ret;

Nope!

Quoted 1 line

This is not easier to read for me. This goto exit jumping and I hate that.

Can the software design direction become feasible to omit the repeated check for the variable “ret” (and further initialisations)?

Regards,
Markus

#8 lore raw

PATCH 4/5 Bluetooth: btmrvl: Delete an unnecessary variable initialisation in btmrvl_sdio_card_to_host()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 11:15:59 +0100

The variable "payload" will eventually be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/bluetooth/btmrvl_sdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btmrvl_sdio.c +1 -1
index 9854addc8e96..05c78fcc13ff 100644
@@ -691,5 +691,5 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	u32 type;
-	u8 *payload = NULL;
+	u8 *payload;
 	struct hci_dev *hdev = priv->btmrvl_dev.hcidev;
 	struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
 
Signature · 1 line
2.16.2
maintainer
#9 lore raw

Re: [PATCH 4/5] Bluetooth: btmrvl: Delete an unnecessary variable initialisation in btmrvl_sdio_card_to_host()

Hi Markus,

Quoted 7 lines

The variable "payload" will eventually be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.

---
drivers/bluetooth/btmrvl_sdio.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#10 lore raw

PATCH 5/5 Bluetooth: btmrvl: Use common error handling code in btmrvl_sdio_download_fw_w_helper()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 11:30:28 +0100

Add a jump target so that the setting of a specific error code is stored only once at the end of this function.

---
 drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +7 -6
index 05c78fcc13ff..24ed62fe2aeb 100644
@@ -601,8 +601,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base0 = 0x%04X(%d)."
 					" Terminating download",
 					base0, base0);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			base1 = sdio_readb(card->func,
 					card->reg->sq_read_base_addr_a1, &ret);
@@ -611,8 +610,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base1 = 0x%04X(%d)."
 					" Terminating download",
 					base1, base1);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 
 			len = (((u16) base1) << 8) | base0;
@@ -638,8 +636,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 			if (count > MAX_WRITE_IOMEM_RETRY) {
 				BT_ERR("FW download failure @%d, "
 					"over max retry count", offset);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			BT_ERR("FW CRC error indicated by the helper: "
 				"len = 0x%04X, txlen = %d", len, txlen);
@@ -681,6 +678,10 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 	kfree(tmpfwbuf);
 	release_firmware(fw_firmware);
 	return ret;
+
+e_io:
+	ret = -EIO;
+	goto done;
 }
 
 static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
Signature · 1 line
2.16.2
maintainer
#11 lore raw

Re: [PATCH 5/5] Bluetooth: btmrvl: Use common error handling code in btmrvl_sdio_download_fw_w_helper()

Hi Markus,

Quoted 46 lines

From: Markus Elfring <[email protected]>
Date: Mon, 12 Mar 2018 11:30:28 +0100

Add a jump target so that the setting of a specific error code is stored only once at the end of this function.

---
drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------

1 file changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +3 -6
index 05c78fcc13ff..24ed62fe2aeb 100644
@@ -601,8 +601,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base0 = 0x%04X(%d)."
 					" Terminating download",
 					base0, base0);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			base1 = sdio_readb(card->func,
 					card->reg->sq_read_base_addr_a1, &ret);
@@ -611,8 +610,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base1 = 0x%04X(%d)."
 					" Terminating download",
 					base1, base1);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 
 			len = (((u16) base1) << 8) | base0;
@@ -638,8 +636,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 			if (count > MAX_WRITE_IOMEM_RETRY) {
 				BT_ERR("FW download failure @%d, "
 					"over max retry count", offset);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			BT_ERR("FW CRC error indicated by the helper: "
 				"len = 0x%04X, txlen = %d", len, txlen);

drivers/bluetooth/btmrvl_sdio.c static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card) · line 685

Quoted 8 lines
drivers/bluetooth/btmrvl_sdio.c +4 -0
@@ -681,6 +678,10 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 	kfree(tmpfwbuf);
 	release_firmware(fw_firmware);
 	return ret;
+
+e_io:
+	ret = -EIO;
+	goto done;
 }

I am not applying this one. I see zero benefit in this change. It is not even saving a single line since it actually is more code.

Regards

Marcel

#12 lore raw

Re: [PATCH 5/5] Bluetooth: btmrvl: Use common error handling code in btmrvl_sdio_download_fw_w_helper()

Quoted 45 lines
Quoted 45 lines

Add a jump target so that the setting of a specific error code is stored only once at the end of this function.

---
drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------

1 file changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmrvl_sdio.c +3 -6
index 05c78fcc13ff..24ed62fe2aeb 100644
@@ -601,8 +601,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base0 = 0x%04X(%d)."
 					" Terminating download",
 					base0, base0);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			base1 = sdio_readb(card->func,
 					card->reg->sq_read_base_addr_a1, &ret);
@@ -611,8 +610,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 					" base1 = 0x%04X(%d)."
 					" Terminating download",
 					base1, base1);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 
 			len = (((u16) base1) << 8) | base0;
@@ -638,8 +636,7 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 			if (count > MAX_WRITE_IOMEM_RETRY) {
 				BT_ERR("FW download failure @%d, "
 					"over max retry count", offset);
-				ret = -EIO;
-				goto done;
+				goto e_io;
 			}
 			BT_ERR("FW CRC error indicated by the helper: "
 				"len = 0x%04X, txlen = %d", len, txlen);
@@ -681,6 +678,10 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
 	kfree(tmpfwbuf);
 	release_firmware(fw_firmware);
Quoted 8 lines

drivers/bluetooth/btmrvl_sdio.c static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card) · line 685

Quoted 6 lines
drivers/bluetooth/btmrvl_sdio.c +4 -0
 	return ret;
+
+e_io:
+	ret = -EIO;
+	goto done;
 }

I am not applying this one. I see zero benefit in this change.

Would you care for a bit of object code reduction in this function implementation.

Quoted 1 line

It is not even saving a single line since it actually is more code.

Should I fiddle with any other source code layout?

Do you find an extra blank line inappropriate before the added jump target in this use case?

Regards,
Markus