2017-07-09 05:43:37

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH 1/2] staging: ccree: remove unnecessary cast on kmalloc

The assignment operator implicitly converts a void pointer to the type of the
pointer it is assigned to.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression * e;
expression arg1, arg2;
type T;
@@

- e=(T*)
+ e=
kmalloc(arg1, arg2);

Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/staging/ccree/ssi_buffer_mgr.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c
index b35871e..18a8694 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -1725,8 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
struct buff_mgr_handle *buff_mgr_handle;
struct device *dev = &drvdata->plat_dev->dev;

- buff_mgr_handle = (struct buff_mgr_handle *)
- kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+ buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
if (!buff_mgr_handle)
return -ENOMEM;

--
2.5.0


2017-07-09 05:46:03

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH 2/2] staging: ccree: use sizeof(*var) in kmalloc

Fix the following checkpatch warning:

CHECK: Prefer kmalloc(sizeof(*buff_mgr_handle)...)
over kmalloc(sizeof(struct buff_mgr_handle)...)

Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/staging/ccree/ssi_buffer_mgr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c
index 18a8694..9caff9b 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -1725,7 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
struct buff_mgr_handle *buff_mgr_handle;
struct device *dev = &drvdata->plat_dev->dev;

- buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+ buff_mgr_handle = kmalloc(sizeof(*buff_mgr_handle), GFP_KERNEL);
if (!buff_mgr_handle)
return -ENOMEM;

--
2.5.0

2017-07-11 13:44:43

by Gilad Ben-Yossef

[permalink] [raw]
Subject: Re: [PATCH 1/2] staging: ccree: remove unnecessary cast on kmalloc

On Sun, Jul 9, 2017 at 8:43 AM, Gustavo A. R. Silva
<[email protected]> wrote:
> The assignment operator implicitly converts a void pointer to the type of the
> pointer it is assigned to.
>
> This issue was detected using Coccinelle and the following semantic patch:
>
> @@
> expression * e;
> expression arg1, arg2;
> type T;
> @@
>
> - e=(T*)
> + e=
> kmalloc(arg1, arg2);
>
> Signed-off-by: Gustavo A. R. Silva <[email protected]>

For both patches:

Acked-by: Gilad Ben-Yossef <[email protected]>

> ---
> drivers/staging/ccree/ssi_buffer_mgr.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c
> index b35871e..18a8694 100644
> --- a/drivers/staging/ccree/ssi_buffer_mgr.c
> +++ b/drivers/staging/ccree/ssi_buffer_mgr.c
> @@ -1725,8 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
> struct buff_mgr_handle *buff_mgr_handle;
> struct device *dev = &drvdata->plat_dev->dev;
>
> - buff_mgr_handle = (struct buff_mgr_handle *)
> - kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
> + buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
> if (!buff_mgr_handle)
> return -ENOMEM;
>
> --
> 2.5.0
>

Thanks,
Gilad



--
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
-- Jean-Baptiste Queru