kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: qca: Use common error handling code in two functions
@ 2024-05-05  8:39 Markus Elfring
  2024-05-05  9:06 ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-05-05  8:39 UTC (permalink / raw)
  To: linux-bluetooth, kernel-janitors, Luiz Augusto von Dentz,
	Marcel Holtmann
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 5 May 2024 10:30:28 +0200

Add a jump target so that the setting of an error code can be better reused
at the end of these function implementations.

This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/bluetooth/btqca.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c
index cc61014ffbc9..1833aaa6d87b 100644
--- a/drivers/bluetooth/btqca.c
+++ b/drivers/bluetooth/btqca.c
@@ -108,10 +108,8 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
 		return err;
 	}

-	if (skb->len < sizeof(*edl)) {
-		err = -EILSEQ;
-		goto out;
-	}
+	if (skb->len < sizeof(*edl))
+		goto e_ilseq;

 	edl = (struct edl_event_hdr *)(skb->data);

@@ -123,17 +121,13 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
 		goto out;
 	}

-	if (skb->len < sizeof(*edl) + 1) {
-		err = -EILSEQ;
-		goto out;
-	}
+	if (skb->len < sizeof(*edl) + 1)
+		goto e_ilseq;

 	build_lbl_len = edl->data[0];

-	if (skb->len < sizeof(*edl) + 1 + build_lbl_len) {
-		err = -EILSEQ;
-		goto out;
-	}
+	if (skb->len < sizeof(*edl) + 1 + build_lbl_len)
+		goto e_ilseq;

 	build_label = kstrndup(&edl->data[1], build_lbl_len, GFP_KERNEL);
 	if (!build_label)
@@ -145,6 +139,10 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
 out:
 	kfree_skb(skb);
 	return err;
+
+e_ilseq:
+	err = -EILSEQ;
+	goto out;
 }

 static int qca_send_patch_config_cmd(struct hci_dev *hdev)
@@ -224,8 +222,7 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
 	edl = skb_pull_data(skb, sizeof(*edl));
 	if (!edl) {
 		bt_dev_err(hdev, "QCA read board ID with no header");
-		err = -EILSEQ;
-		goto out;
+		goto e_ilseq;
 	}

 	if (edl->cresp != EDL_CMD_REQ_RES_EVT ||
@@ -235,10 +232,8 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
 		goto out;
 	}

-	if (skb->len < 3) {
-		err = -EILSEQ;
-		goto out;
-	}
+	if (skb->len < 3)
+		goto e_ilseq;

 	*bid = (edl->data[1] << 8) + edl->data[2];
 	bt_dev_dbg(hdev, "%s: bid = %x", __func__, *bid);
@@ -246,6 +241,10 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
 out:
 	kfree_skb(skb);
 	return err;
+
+e_ilseq:
+	err = -EILSEQ;
+	goto out;
 }

 int qca_send_pre_shutdown_cmd(struct hci_dev *hdev)
--
2.44.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bluetooth: qca: Use common error handling code in two functions
  2024-05-05  8:39 [PATCH] Bluetooth: qca: Use common error handling code in two functions Markus Elfring
@ 2024-05-05  9:06 ` Julia Lawall
  2024-05-05 10:30   ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2024-05-05  9:06 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-bluetooth, kernel-janitors, Luiz Augusto von Dentz,
	Marcel Holtmann, LKML



On Sun, 5 May 2024, Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 5 May 2024 10:30:28 +0200
>
> Add a jump target so that the setting of an error code can be better reused
> at the end of these function implementations.
>
> This issue was transformed by using the Coccinelle software.

This reduces readability, and backwards jumps are rarely desirable.

julia

>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/bluetooth/btqca.c | 35 +++++++++++++++++------------------
>  1 file changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c
> index cc61014ffbc9..1833aaa6d87b 100644
> --- a/drivers/bluetooth/btqca.c
> +++ b/drivers/bluetooth/btqca.c
> @@ -108,10 +108,8 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
>  		return err;
>  	}
>
> -	if (skb->len < sizeof(*edl)) {
> -		err = -EILSEQ;
> -		goto out;
> -	}
> +	if (skb->len < sizeof(*edl))
> +		goto e_ilseq;
>
>  	edl = (struct edl_event_hdr *)(skb->data);
>
> @@ -123,17 +121,13 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
>  		goto out;
>  	}
>
> -	if (skb->len < sizeof(*edl) + 1) {
> -		err = -EILSEQ;
> -		goto out;
> -	}
> +	if (skb->len < sizeof(*edl) + 1)
> +		goto e_ilseq;
>
>  	build_lbl_len = edl->data[0];
>
> -	if (skb->len < sizeof(*edl) + 1 + build_lbl_len) {
> -		err = -EILSEQ;
> -		goto out;
> -	}
> +	if (skb->len < sizeof(*edl) + 1 + build_lbl_len)
> +		goto e_ilseq;
>
>  	build_label = kstrndup(&edl->data[1], build_lbl_len, GFP_KERNEL);
>  	if (!build_label)
> @@ -145,6 +139,10 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
>  out:
>  	kfree_skb(skb);
>  	return err;
> +
> +e_ilseq:
> +	err = -EILSEQ;
> +	goto out;
>  }
>
>  static int qca_send_patch_config_cmd(struct hci_dev *hdev)
> @@ -224,8 +222,7 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
>  	edl = skb_pull_data(skb, sizeof(*edl));
>  	if (!edl) {
>  		bt_dev_err(hdev, "QCA read board ID with no header");
> -		err = -EILSEQ;
> -		goto out;
> +		goto e_ilseq;
>  	}
>
>  	if (edl->cresp != EDL_CMD_REQ_RES_EVT ||
> @@ -235,10 +232,8 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
>  		goto out;
>  	}
>
> -	if (skb->len < 3) {
> -		err = -EILSEQ;
> -		goto out;
> -	}
> +	if (skb->len < 3)
> +		goto e_ilseq;
>
>  	*bid = (edl->data[1] << 8) + edl->data[2];
>  	bt_dev_dbg(hdev, "%s: bid = %x", __func__, *bid);
> @@ -246,6 +241,10 @@ static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
>  out:
>  	kfree_skb(skb);
>  	return err;
> +
> +e_ilseq:
> +	err = -EILSEQ;
> +	goto out;
>  }
>
>  int qca_send_pre_shutdown_cmd(struct hci_dev *hdev)
> --
> 2.44.0
>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bluetooth: qca: Use common error handling code in two functions
  2024-05-05  9:06 ` Julia Lawall
@ 2024-05-05 10:30   ` Markus Elfring
  2024-05-05 10:37     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-05-05 10:30 UTC (permalink / raw)
  To: Julia Lawall, Luiz Augusto von Dentz, Marcel Holtmann,
	linux-bluetooth, kernel-janitors
  Cc: LKML

>> Add a jump target so that the setting of an error code can be better reused
>> at the end of these function implementations.
> This reduces readability, and backwards jumps are rarely desirable.

Would you like to support any other design approaches better for
the reduction of questionable source code duplication?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bluetooth: qca: Use common error handling code in two functions
  2024-05-05 10:30   ` Markus Elfring
@ 2024-05-05 10:37     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2024-05-05 10:37 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Luiz Augusto von Dentz, Marcel Holtmann, linux-bluetooth,
	kernel-janitors, LKML

[-- Attachment #1: Type: text/plain, Size: 584 bytes --]



On Sun, 5 May 2024, Markus Elfring wrote:

> >> Add a jump target so that the setting of an error code can be better reused
> >> at the end of these function implementations.
> …
> > This reduces readability, and backwards jumps are rarely desirable.
>
> Would you like to support any other design approaches better for
> the reduction of questionable source code duplication?

Maybe cleanup.h can be used to get rid of the kfree_skb.  I have no idea.

It would be nice to keep the patch in the message so that one could see
what is being discussed from the message itself.

julia

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-05 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-05  8:39 [PATCH] Bluetooth: qca: Use common error handling code in two functions Markus Elfring
2024-05-05  9:06 ` Julia Lawall
2024-05-05 10:30   ` Markus Elfring
2024-05-05 10:37     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).