[v2] Bluetooth: Use kzalloc instead of kmalloc/memset

Message ID 20221029214058.25159-1-tegongkang@gmail.com
State New
Headers
Series [v2] Bluetooth: Use kzalloc instead of kmalloc/memset |

Commit Message

Kang Minchul Oct. 29, 2022, 9:40 p.m. UTC
  This commit replace kmalloc + memset to kzalloc
for better code readability and simplicity.

Following messages are related cocci warnings.

WARNING: kzalloc should be used for d, instead of kmalloc/memset

Signed-off-by: Kang Minchul <tegongkang@gmail.com>
---
V1 -> V2: Change subject prefix

 net/bluetooth/hci_conn.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Paul Menzel Oct. 30, 2022, 10:11 a.m. UTC | #1
Dear Kang,


Thank you for the patch.


Am 29.10.22 um 23:40 schrieb Kang Minchul:
> This commit replace kmalloc + memset to kzalloc

replace*s*

(Though starting with “This commit …” is redundant.

> for better code readability and simplicity.
> 
> Following messages are related cocci warnings.

Maybe: This addresse the cocci warning below.

> WARNING: kzalloc should be used for d, instead of kmalloc/memset
> 
> Signed-off-by: Kang Minchul <tegongkang@gmail.com>
> ---
> V1 -> V2: Change subject prefix
> 
>   net/bluetooth/hci_conn.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 7a59c4487050..287d313aa312 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -824,11 +824,10 @@ static int hci_le_terminate_big(struct hci_dev *hdev, u8 big, u8 bis)
>   
>   	bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", big, bis);
>   
> -	d = kmalloc(sizeof(*d), GFP_KERNEL);
> +	d = kzalloc(sizeof(*d), GFP_KERNEL);
>   	if (!d)
>   		return -ENOMEM;
>   
> -	memset(d, 0, sizeof(*d));
>   	d->big = big;
>   	d->bis = bis;
>   
> @@ -861,11 +860,10 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16 sync_handle)
>   
>   	bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, sync_handle);
>   
> -	d = kmalloc(sizeof(*d), GFP_KERNEL);
> +	d = kzalloc(sizeof(*d), GFP_KERNEL);
>   	if (!d)
>   		return -ENOMEM;
>   
> -	memset(d, 0, sizeof(*d));
>   	d->big = big;
>   	d->sync_handle = sync_handle;

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul
  
Kang Minchul Oct. 30, 2022, 10:29 a.m. UTC | #2
> Am 29.10.22 um 23:40 schrieb Kang Minchul:
> > This commit replace kmalloc + memset to kzalloc
>
> replace*s*
>
> (Though starting with “This commit …” is redundant.
>
> > for better code readability and simplicity.
> >
> > Following messages are related cocci warnings.
>
> Maybe: This addresse the cocci warning below.
>
> > WARNING: kzalloc should be used for d, instead of kmalloc/memset
> >
> > Signed-off-by: Kang Minchul <tegongkang@gmail.com>
> > ---
> > V1 -> V2: Change subject prefix
> >
> >   net/bluetooth/hci_conn.c | 6 ++----
> >   1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> > index 7a59c4487050..287d313aa312 100644
> > --- a/net/bluetooth/hci_conn.c
> > +++ b/net/bluetooth/hci_conn.c
> > @@ -824,11 +824,10 @@ static int hci_le_terminate_big(struct hci_dev *hdev, u8 big, u8 bis)
> >
> >       bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", big, bis);
> >
> > -     d = kmalloc(sizeof(*d), GFP_KERNEL);
> > +     d = kzalloc(sizeof(*d), GFP_KERNEL);
> >       if (!d)
> >               return -ENOMEM;
> >
> > -     memset(d, 0, sizeof(*d));
> >       d->big = big;
> >       d->bis = bis;
> >
> > @@ -861,11 +860,10 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16 sync_handle)
> >
> >       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, sync_handle);
> >
> > -     d = kmalloc(sizeof(*d), GFP_KERNEL);
> > +     d = kzalloc(sizeof(*d), GFP_KERNEL);
> >       if (!d)
> >               return -ENOMEM;
> >
> > -     memset(d, 0, sizeof(*d));
> >       d->big = big;
> >       d->sync_handle = sync_handle;
>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
>
>
> Kind regards,
>
> Paul

Thank you so much for your feedback!
Should I amend the previous commit message and resend PATCH v3?

regards,

Kang Minchul
  
Kang Minchul Oct. 30, 2022, 6:16 p.m. UTC | #3
I just amended the message and sent patch v3.

Again, thanks for the feedback.

regards,

Kang Minchul
  

Patch

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7a59c4487050..287d313aa312 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -824,11 +824,10 @@  static int hci_le_terminate_big(struct hci_dev *hdev, u8 big, u8 bis)
 
 	bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", big, bis);
 
-	d = kmalloc(sizeof(*d), GFP_KERNEL);
+	d = kzalloc(sizeof(*d), GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 
-	memset(d, 0, sizeof(*d));
 	d->big = big;
 	d->bis = bis;
 
@@ -861,11 +860,10 @@  static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16 sync_handle)
 
 	bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, sync_handle);
 
-	d = kmalloc(sizeof(*d), GFP_KERNEL);
+	d = kzalloc(sizeof(*d), GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 
-	memset(d, 0, sizeof(*d));
 	d->big = big;
 	d->sync_handle = sync_handle;