[v1] Bluetooth: Optimize devcoredump API hci_devcd_init()

Message ID 1681213778-31754-1-git-send-email-quic_zijuhu@quicinc.com
State New
Headers
Series [v1] Bluetooth: Optimize devcoredump API hci_devcd_init() |

Commit Message

quic_zijuhu April 11, 2023, 11:49 a.m. UTC
  API hci_devcd_init() stores u32 type to memory without specific byte
order, let us store with little endian in order to be loaded and
parsed by devcoredump core rightly.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 net/bluetooth/coredump.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
  

Comments

Luiz Augusto von Dentz April 14, 2023, 9:03 p.m. UTC | #1
Hi Zijun,

On Tue, Apr 11, 2023 at 4:49 AM Zijun Hu <quic_zijuhu@quicinc.com> wrote:
>
> API hci_devcd_init() stores u32 type to memory without specific byte
> order, let us store with little endian in order to be loaded and
> parsed by devcoredump core rightly.

This looks like a fix if devcoredump expects little endian, so I'd
suggest rephrasing to state it in the subject line, also add the Fixes
tag for the commit that introduces this problem.

> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  net/bluetooth/coredump.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/net/bluetooth/coredump.c b/net/bluetooth/coredump.c
> index 08fa98505454..d2d2624ec708 100644
> --- a/net/bluetooth/coredump.c
> +++ b/net/bluetooth/coredump.c
> @@ -5,6 +5,7 @@
>
>  #include <linux/devcoredump.h>
>
> +#include <asm/unaligned.h>
>  #include <net/bluetooth/bluetooth.h>
>  #include <net/bluetooth/hci_core.h>
>
> @@ -180,25 +181,25 @@ static int hci_devcd_prepare(struct hci_dev *hdev, u32 dump_size)
>
>  static void hci_devcd_handle_pkt_init(struct hci_dev *hdev, struct sk_buff *skb)
>  {
> -       u32 *dump_size;
> +       u32 dump_size;
>
>         if (hdev->dump.state != HCI_DEVCOREDUMP_IDLE) {
>                 DBG_UNEXPECTED_STATE();
>                 return;
>         }
>
> -       if (skb->len != sizeof(*dump_size)) {
> +       if (skb->len != sizeof(dump_size)) {
>                 bt_dev_dbg(hdev, "Invalid dump init pkt");
>                 return;
>         }
>
> -       dump_size = skb_pull_data(skb, sizeof(*dump_size));
> -       if (!*dump_size) {
> +       dump_size = get_unaligned_le32(skb_pull_data(skb, 4));
> +       if (!dump_size) {
>                 bt_dev_err(hdev, "Zero size dump init pkt");
>                 return;
>         }
>
> -       if (hci_devcd_prepare(hdev, *dump_size)) {
> +       if (hci_devcd_prepare(hdev, dump_size)) {
>                 bt_dev_err(hdev, "Failed to prepare for dump");
>                 return;
>         }
> @@ -441,7 +442,7 @@ int hci_devcd_init(struct hci_dev *hdev, u32 dump_size)
>                 return -ENOMEM;
>
>         hci_dmp_cb(skb)->pkt_type = HCI_DEVCOREDUMP_PKT_INIT;
> -       skb_put_data(skb, &dump_size, sizeof(dump_size));
> +       put_unaligned_le32(dump_size, skb_put(skb, 4));
>
>         skb_queue_tail(&hdev->dump.dump_q, skb);
>         queue_work(hdev->workqueue, &hdev->dump.dump_rx);
> --
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
>
  
patchwork-bot+bluetooth@kernel.org April 17, 2023, 6:30 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 11 Apr 2023 19:49:38 +0800 you wrote:
> API hci_devcd_init() stores u32 type to memory without specific byte
> order, let us store with little endian in order to be loaded and
> parsed by devcoredump core rightly.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  net/bluetooth/coredump.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)

Here is the summary with links:
  - [v1] Bluetooth: Optimize devcoredump API hci_devcd_init()
    https://git.kernel.org/bluetooth/bluetooth-next/c/61cad9af36db

You are awesome, thank you!
  

Patch

diff --git a/net/bluetooth/coredump.c b/net/bluetooth/coredump.c
index 08fa98505454..d2d2624ec708 100644
--- a/net/bluetooth/coredump.c
+++ b/net/bluetooth/coredump.c
@@ -5,6 +5,7 @@ 
 
 #include <linux/devcoredump.h>
 
+#include <asm/unaligned.h>
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 
@@ -180,25 +181,25 @@  static int hci_devcd_prepare(struct hci_dev *hdev, u32 dump_size)
 
 static void hci_devcd_handle_pkt_init(struct hci_dev *hdev, struct sk_buff *skb)
 {
-	u32 *dump_size;
+	u32 dump_size;
 
 	if (hdev->dump.state != HCI_DEVCOREDUMP_IDLE) {
 		DBG_UNEXPECTED_STATE();
 		return;
 	}
 
-	if (skb->len != sizeof(*dump_size)) {
+	if (skb->len != sizeof(dump_size)) {
 		bt_dev_dbg(hdev, "Invalid dump init pkt");
 		return;
 	}
 
-	dump_size = skb_pull_data(skb, sizeof(*dump_size));
-	if (!*dump_size) {
+	dump_size = get_unaligned_le32(skb_pull_data(skb, 4));
+	if (!dump_size) {
 		bt_dev_err(hdev, "Zero size dump init pkt");
 		return;
 	}
 
-	if (hci_devcd_prepare(hdev, *dump_size)) {
+	if (hci_devcd_prepare(hdev, dump_size)) {
 		bt_dev_err(hdev, "Failed to prepare for dump");
 		return;
 	}
@@ -441,7 +442,7 @@  int hci_devcd_init(struct hci_dev *hdev, u32 dump_size)
 		return -ENOMEM;
 
 	hci_dmp_cb(skb)->pkt_type = HCI_DEVCOREDUMP_PKT_INIT;
-	skb_put_data(skb, &dump_size, sizeof(dump_size));
+	put_unaligned_le32(dump_size, skb_put(skb, 4));
 
 	skb_queue_tail(&hdev->dump.dump_q, skb);
 	queue_work(hdev->workqueue, &hdev->dump.dump_rx);