netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shaozhengchao <shaozhengchao@huawei.com>
To: <linux-bluetooth@vger.kernel.org>, <netdev@vger.kernel.org>,
	<marcel@holtmann.org>, <johan.hedberg@gmail.com>,
	<luiz.dentz@gmail.com>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>
Cc: <brian.gix@intel.com>, <weiyongjun1@huawei.com>, <yuehaibing@huawei.com>
Subject: Re: [PATCH v2] Bluetooth: hci_sync: fix memory leak in hci_update_adv_data()
Date: Tue, 10 Jan 2023 15:05:11 +0800	[thread overview]
Message-ID: <b44a75c9-078a-d4ed-8313-45428e8ec8b0@huawei.com> (raw)
In-Reply-To: <20230110064420.3409168-1-shaozhengchao@huawei.com>


Sorry for Repeatedly senting. Please ignore this patch.

On 2023/1/10 14:44, Zhengchao Shao wrote:
> When hci_cmd_sync_queue() failed in hci_update_adv_data(), inst_ptr is
> not freed, which will cause memory leak. ERR_PTR/PTR_ERR is used to
> replace memory allocation to simplify code.
> 
> Fixes: 651cd3d65b0f ("Bluetooth: convert hci_update_adv_data to hci_sync")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
> v2: Use ERR_PTR/PTR_ERR to replace memory allocation
> ---
>   net/bluetooth/hci_sync.c | 10 ++--------
>   1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
> index 9e2d7e4b850c..8744bbecac9e 100644
> --- a/net/bluetooth/hci_sync.c
> +++ b/net/bluetooth/hci_sync.c
> @@ -6187,20 +6187,14 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
>   
>   static int _update_adv_data_sync(struct hci_dev *hdev, void *data)
>   {
> -	u8 instance = *(u8 *)data;
> -
> -	kfree(data);
> +	u8 instance = PTR_ERR(data);
>   
>   	return hci_update_adv_data_sync(hdev, instance);
>   }
>   
>   int hci_update_adv_data(struct hci_dev *hdev, u8 instance)
>   {
> -	u8 *inst_ptr = kmalloc(1, GFP_KERNEL);
> -
> -	if (!inst_ptr)
> -		return -ENOMEM;
> +	u8 *inst_ptr = ERR_PTR(instance);
>   
> -	*inst_ptr = instance;
>   	return hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL);
>   }

      reply	other threads:[~2023-01-10  7:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10  6:44 [PATCH v2] Bluetooth: hci_sync: fix memory leak in hci_update_adv_data() Zhengchao Shao
2023-01-10  7:05 ` shaozhengchao [this message]

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=b44a75c9-078a-d4ed-8313-45428e8ec8b0@huawei.com \
    --to=shaozhengchao@huawei.com \
    --cc=brian.gix@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johan.hedberg@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=weiyongjun1@huawei.com \
    --cc=yuehaibing@huawei.com \
    /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 NNTP newsgroup(s).