Kernel-Janitors Archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-bluetooth@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Marcel Holtmann <marcel@holtmann.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] Bluetooth: qca: Use common error handling code in two functions
Date: Sun, 5 May 2024 10:39:02 +0200	[thread overview]
Message-ID: <fd9f738e-8e78-4afb-96fd-907f72fb4e13@web.de> (raw)

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


             reply	other threads:[~2024-05-05  8:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-05  8:39 Markus Elfring [this message]
2024-05-05  9:06 ` [PATCH] Bluetooth: qca: Use common error handling code in two functions Julia Lawall
2024-05-05 10:30   ` Markus Elfring
2024-05-05 10:37     ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd9f738e-8e78-4afb-96fd-907f72fb4e13@web.de \
    --to=markus.elfring@web.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).