2018-03-12 11:30:08

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/5] 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(-)

--
2.16.2


2018-03-13 07:55:57

by SF Markus Elfring

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

>> Add a jump target so that the setting of a specific error code is stored
>> only once at the end of this function.
>>
>> Signed-off-by: Markus Elfring <[email protected]>
>> ---
>> drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------
>> 1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
>> index 05c78fcc13ff..24ed62fe2aeb 100644
>> --- a/drivers/bluetooth/btmrvl_sdio.c
>> +++ b/drivers/bluetooth/btmrvl_sdio.c
>> @@ -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;
>> }
>
> 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.


> 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

2018-03-13 07:46:33

by SF Markus Elfring

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

>> @@ -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;
>
> Nope!
>
> 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

2018-03-12 16:18:31

by Marcel Holtmann

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

Hi Markus,

> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/bluetooth/btmrvl_sdio.c | 50 ++++++++++++++++-------------------------
> 1 file changed, 19 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
> index 0f020254fd39..df2a04bd8428 100644
> --- a/drivers/bluetooth/btmrvl_sdio.c
> +++ b/drivers/bluetooth/btmrvl_sdio.c
> @@ -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:

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

2018-03-12 16:12:51

by Marcel Holtmann

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

Hi Markus,

> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/bluetooth/btmrvl_sdio.c | 35 ++++++++++++++++++-----------------
> 1 file changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
> index 84c222abf0f7..9854addc8e96 100644
> --- a/drivers/bluetooth/btmrvl_sdio.c
> +++ b/drivers/bluetooth/btmrvl_sdio.c
> @@ -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;

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

2018-03-12 16:11:25

by Marcel Holtmann

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

Hi Markus,

> The variable "payload" will eventually be set to an appropriate pointer
> a bit later. Thus omit the explicit initialisation at the beginning.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/bluetooth/btmrvl_sdio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

2018-03-12 16:11:22

by Marcel Holtmann

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

Hi Markus,

> The local variable "ret" will be set to an appropriate value a bit later.
> Thus omit the explicit initialisation at the beginning.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/bluetooth/btmrvl_sdio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

2018-03-12 16:06:15

by Marcel Holtmann

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

Hi Markus,

> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
> index 05c78fcc13ff..24ed62fe2aeb 100644
> --- a/drivers/bluetooth/btmrvl_sdio.c
> +++ b/drivers/bluetooth/btmrvl_sdio.c
> @@ -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;
> }

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

2018-03-12 11:35:33

by SF Markus Elfring

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

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/bluetooth/btmrvl_sdio.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 05c78fcc13ff..24ed62fe2aeb 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -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)
--
2.16.2

2018-03-12 11:34:15

by SF Markus Elfring

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

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/bluetooth/btmrvl_sdio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 9854addc8e96..05c78fcc13ff 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -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;

--
2.16.2

2018-03-12 11:33:26

by SF Markus Elfring

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

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/bluetooth/btmrvl_sdio.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 84c222abf0f7..9854addc8e96 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -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;
}

--
2.16.2

2018-03-12 11:32:32

by SF Markus Elfring

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

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/bluetooth/btmrvl_sdio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index df2a04bd8428..84c222abf0f7 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -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!");
--
2.16.2

2018-03-12 11:31:44

by SF Markus Elfring

[permalink] [raw]
Subject: [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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/bluetooth/btmrvl_sdio.c | 50 ++++++++++++++++-------------------------
1 file changed, 19 insertions(+), 31 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 0f020254fd39..df2a04bd8428 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -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:
--
2.16.2