[PATCH] staging: rtl8712: Fix style issues in rtl871x_io.c

Manisha Singh posted 1 patch 1 year, 3 months ago
drivers/staging/rtl8712/rtl871x_io.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] staging: rtl8712: Fix style issues in rtl871x_io.c
Posted by Manisha Singh 1 year, 3 months ago
This patch addresses style issues reported by checkpatch.pl in
drivers/staging/rtl8712/rtl871x_io.c:

1. Avoid Multiple Assignments: The original line had multiple
   assignments in a single statement. This is generally discouraged
   for clarity and maintainability. The code has been refactored to
   use separate statements for each assignment.

2. Prefer `sizeof(*pintf_hdl->pintfpriv)` Over
   `sizeof(struct intf_priv)`: Updated the memory allocation call to
   use `sizeof(*pintf_hdl->pintfpriv)` instead of
   `sizeof(struct intf_priv)`. This is considered better practice as it
   automatically adjusts if the type of `pintf_hdl->pintfpriv` changes,
   reducing the risk of mismatches and improving maintainability.

Changes made:
- Replaced the original line with two separate lines for allocation and
  assignment.
- Updated `kmalloc` to use `sizeof(*pintf_hdl->pintfpriv)` for the
  allocation size.

These changes improve code readability and maintain consistency with
coding standards.

Signed-off-by: Manisha Singh <masingh.linux@gmail.com>
---
 drivers/staging/rtl8712/rtl871x_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_io.c b/drivers/staging/rtl8712/rtl871x_io.c
index 6789a4c98564..b81e9b06725c 100644
--- a/drivers/staging/rtl8712/rtl871x_io.c
+++ b/drivers/staging/rtl8712/rtl871x_io.c
@@ -48,8 +48,8 @@ static uint _init_intf_hdl(struct _adapter *padapter,
 	set_intf_funs = &(r8712_usb_set_intf_funs);
 	set_intf_ops = &r8712_usb_set_intf_ops;
 	init_intf_priv = &r8712_usb_init_intf_priv;
-	pintf_priv = pintf_hdl->pintfpriv = kmalloc(sizeof(struct intf_priv),
-						    GFP_ATOMIC);
+	pintf_priv = kmalloc(sizeof(*pintf_hdl->pintfpriv), GFP_ATOMIC);
+	pintf_hdl->pintfpriv = pintf_priv;
 	if (!pintf_priv)
 		goto _init_intf_hdl_fail;
 	pintf_hdl->adapter = (u8 *)padapter;
-- 
2.43.0
Re: [PATCH] staging: rtl8712: Fix style issues in rtl871x_io.c
Posted by Philipp Hortmann 1 year, 3 months ago
On 8/26/24 20:52, Manisha Singh wrote:
> This patch addresses style issues reported by checkpatch.pl in
> drivers/staging/rtl8712/rtl871x_io.c:
> 
> 1. Avoid Multiple Assignments: The original line had multiple
>     assignments in a single statement. This is generally discouraged
>     for clarity and maintainability. The code has been refactored to
>     use separate statements for each assignment.
> 
> 2. Prefer `sizeof(*pintf_hdl->pintfpriv)` Over
>     `sizeof(struct intf_priv)`: Updated the memory allocation call to
>     use `sizeof(*pintf_hdl->pintfpriv)` instead of
>     `sizeof(struct intf_priv)`. This is considered better practice as it
>     automatically adjusts if the type of `pintf_hdl->pintfpriv` changes,
>     reducing the risk of mismatches and improving maintainability.
> 
Hi Manisha,

please do just one change at a time. The 1. and 2. indicates that you 
are doing two different things.

> Changes made:
> - Replaced the original line with two separate lines for allocation and
>    assignment.
> - Updated `kmalloc` to use `sizeof(*pintf_hdl->pintfpriv)` for the
>    allocation size.
> 
> These changes improve code readability and maintain consistency with
> coding standards.

Do not describe so much what you do. What you do can be seen in the 
patch. The most important thing to describe is the __why__. When 
possible just use 2-3 Lines in the description.

> 
> Signed-off-by: Manisha Singh <masingh.linux@gmail.com>
> ---
>   drivers/staging/rtl8712/rtl871x_io.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/rtl871x_io.c b/drivers/staging/rtl8712/rtl871x_io.c
> index 6789a4c98564..b81e9b06725c 100644
> --- a/drivers/staging/rtl8712/rtl871x_io.c
> +++ b/drivers/staging/rtl8712/rtl871x_io.c
> @@ -48,8 +48,8 @@ static uint _init_intf_hdl(struct _adapter *padapter,
>   	set_intf_funs = &(r8712_usb_set_intf_funs);
>   	set_intf_ops = &r8712_usb_set_intf_ops;
>   	init_intf_priv = &r8712_usb_init_intf_priv;
> -	pintf_priv = pintf_hdl->pintfpriv = kmalloc(sizeof(struct intf_priv),
> -						    GFP_ATOMIC);
> +	pintf_priv = kmalloc(sizeof(*pintf_hdl->pintfpriv), GFP_ATOMIC);
> +	pintf_hdl->pintfpriv = pintf_priv;
>   	if (!pintf_priv)
>   		goto _init_intf_hdl_fail;
>   	pintf_hdl->adapter = (u8 *)padapter;

If you send in a second version of this patch please use a change 
history. Description from Dan under:
https://staticthinking.wordpress.com/2022/07/27/how-to-send-a-v2-patch/

Thanks for your support.

Bye Philipp