Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread Paul Bolle
On Wed, 2016-09-28 at 18:38 +0200, SF Markus Elfring wrote:
> > I'm not going to change code just because some checker suggests to
> > do so.
> 
> The script "checkpatch.pl" can point information out like the
> following.
> 
> WARNING: Prefer kmalloc_array over kmalloc with multiply

Am I being trolled?


Paul Bolle


Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread Paul Bolle
On Wed, 2016-09-28 at 18:38 +0200, SF Markus Elfring wrote:
> > I'm not going to change code just because some checker suggests to
> > do so.
> 
> The script "checkpatch.pl" can point information out like the
> following.
> 
> WARNING: Prefer kmalloc_array over kmalloc with multiply

Am I being trolled?


Paul Bolle


Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread SF Markus Elfring
>> * Multiplications for the size determination of memory allocations
>>   indicated that array data structures should be processed.
>>   Thus use the corresponding function "kmalloc_array".
> 
> Was the current code incorrect?

I suggest to use a safer interface for array allocations.


> What makes kmalloc_array() better?

1. How do you think about the safety checks that this function provides?

2. Will you be also affected by further software evolution here?
   2016-07-26
   mm: faster kmalloc_array(), kcalloc()
   
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=91c6a05f72a996bee5133e76374ab3ad7d3b9b72


> I'm not going to change code just because some checker suggests to do so.

The script "checkpatch.pl" can point information out like the following.

WARNING: Prefer kmalloc_array over kmalloc with multiply


>>   This issue was detected by using the Coccinelle software.
> 
> So? And which coccinelle script was actually used?

How do you think about to look into related information sources?
https://github.com/coccinelle/coccinelle/issues/81

Would you like to experiment any further with an excerpt?


@replacement1@
expression count, target;
type T;
@@
 target =
- kmalloc(sizeof(T) * (count)
+ kmalloc_array(count, sizeof(T)
, ...);

@replacement2@
expression count, pointer, target;
@@
 target =
- kmalloc(sizeof(*pointer) * (count)
+ kmalloc_array(count, sizeof(*pointer)
, ...);


> I couldn't spot a coccinelle script doing that in the current tree.

This is true for such a software update opportunity.


>> * Replace the specification of a data structure by a pointer dereference
>>   to make the corresponding size determination a bit safer according to
>>   the Linux coding style convention.
> 
> I'm not happy with you mixing this with the above, less trivial, change.

I find that it is a useful combination. - A parameter is adjusted together
with a special function name.


>> -drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
>> +drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
> 
> For "minors" the same holds as for "channels", above.
> 
> And you snuck in a parentheses change. That should have probably been
> merged with 5/5.

Would you prefer to add them in another update step?

Regards,
Markus


Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread SF Markus Elfring
>> * Multiplications for the size determination of memory allocations
>>   indicated that array data structures should be processed.
>>   Thus use the corresponding function "kmalloc_array".
> 
> Was the current code incorrect?

I suggest to use a safer interface for array allocations.


> What makes kmalloc_array() better?

1. How do you think about the safety checks that this function provides?

2. Will you be also affected by further software evolution here?
   2016-07-26
   mm: faster kmalloc_array(), kcalloc()
   
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=91c6a05f72a996bee5133e76374ab3ad7d3b9b72


> I'm not going to change code just because some checker suggests to do so.

The script "checkpatch.pl" can point information out like the following.

WARNING: Prefer kmalloc_array over kmalloc with multiply


>>   This issue was detected by using the Coccinelle software.
> 
> So? And which coccinelle script was actually used?

How do you think about to look into related information sources?
https://github.com/coccinelle/coccinelle/issues/81

Would you like to experiment any further with an excerpt?


@replacement1@
expression count, target;
type T;
@@
 target =
- kmalloc(sizeof(T) * (count)
+ kmalloc_array(count, sizeof(T)
, ...);

@replacement2@
expression count, pointer, target;
@@
 target =
- kmalloc(sizeof(*pointer) * (count)
+ kmalloc_array(count, sizeof(*pointer)
, ...);


> I couldn't spot a coccinelle script doing that in the current tree.

This is true for such a software update opportunity.


>> * Replace the specification of a data structure by a pointer dereference
>>   to make the corresponding size determination a bit safer according to
>>   the Linux coding style convention.
> 
> I'm not happy with you mixing this with the above, less trivial, change.

I find that it is a useful combination. - A parameter is adjusted together
with a special function name.


>> -drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
>> +drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
> 
> For "minors" the same holds as for "channels", above.
> 
> And you snuck in a parentheses change. That should have probably been
> merged with 5/5.

Would you prefer to add them in another update step?

Regards,
Markus


Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread Paul Bolle
On Mon, 2016-09-26 at 17:38 +0200, SF Markus Elfring wrote:
> * Multiplications for the size determination of memory allocations
>   indicated that array data structures should be processed.
>   Thus use the corresponding function "kmalloc_array".

Was the current code incorrect? What makes kmalloc_array() better? None
of this is obvious to me.

I'm not going to change code just because some checker suggests to do
so.

>   This issue was detected by using the Coccinelle software.

So? And which coccinelle script was actually used? I couldn't spot a
coccinelle script doing that in the current tree.

> * Replace the specification of a data structure by a pointer dereference
>   to make the corresponding size determination a bit safer according to
>   the Linux coding style convention.

I'm not happy with you mixing this with the above, less trivial,
change.

> Signed-off-by: Markus Elfring 

> --- a/drivers/isdn/gigaset/common.c
> +++ b/drivers/isdn/gigaset/common.c
> @@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver 
> *drv, int channels,
>  
>   cs->mode = M_UNKNOWN;
>   cs->mstate = MS_UNINITIALIZED;
> -

Unrelated whitespace change.

> - cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
> + cs->bcs = kmalloc_array(channels, sizeof(*cs->bcs), GFP_KERNEL);

For the record: "channels" is basically hardcoded in the three gigaset
hardware drivers.

>   cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
>   if (!cs->bcs || !cs->inbuf) {
>   pr_err("out of memory\n");
> @@ -1089,8 +1088,7 @@ struct gigaset_driver
> *gigaset_initdriver(unsigned minor, unsigned minors,
>   drv->ops = ops;
>   drv->owner = owner;
>   INIT_LIST_HEAD(>list);
> -

Again unrelated whitespace change.

> - drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
> + drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);

For "minors" the same holds as for "channels", above.

And you snuck in a parentheses change. That should have probably been
merged with 5/5.

>   if (!drv->cs)
>   goto error;


Paul Bolle


Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-28 Thread Paul Bolle
On Mon, 2016-09-26 at 17:38 +0200, SF Markus Elfring wrote:
> * Multiplications for the size determination of memory allocations
>   indicated that array data structures should be processed.
>   Thus use the corresponding function "kmalloc_array".

Was the current code incorrect? What makes kmalloc_array() better? None
of this is obvious to me.

I'm not going to change code just because some checker suggests to do
so.

>   This issue was detected by using the Coccinelle software.

So? And which coccinelle script was actually used? I couldn't spot a
coccinelle script doing that in the current tree.

> * Replace the specification of a data structure by a pointer dereference
>   to make the corresponding size determination a bit safer according to
>   the Linux coding style convention.

I'm not happy with you mixing this with the above, less trivial,
change.

> Signed-off-by: Markus Elfring 

> --- a/drivers/isdn/gigaset/common.c
> +++ b/drivers/isdn/gigaset/common.c
> @@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver 
> *drv, int channels,
>  
>   cs->mode = M_UNKNOWN;
>   cs->mstate = MS_UNINITIALIZED;
> -

Unrelated whitespace change.

> - cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
> + cs->bcs = kmalloc_array(channels, sizeof(*cs->bcs), GFP_KERNEL);

For the record: "channels" is basically hardcoded in the three gigaset
hardware drivers.

>   cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
>   if (!cs->bcs || !cs->inbuf) {
>   pr_err("out of memory\n");
> @@ -1089,8 +1088,7 @@ struct gigaset_driver
> *gigaset_initdriver(unsigned minor, unsigned minors,
>   drv->ops = ops;
>   drv->owner = owner;
>   INIT_LIST_HEAD(>list);
> -

Again unrelated whitespace change.

> - drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
> + drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);

For "minors" the same holds as for "channels", above.

And you snuck in a parentheses change. That should have probably been
merged with 5/5.

>   if (!drv->cs)
>   goto error;


Paul Bolle


[PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-26 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 25 Sep 2016 22:22:04 +0200

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/isdn/gigaset/common.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 7c78144..cecbb6a 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver 
*drv, int channels,
 
cs->mode = M_UNKNOWN;
cs->mstate = MS_UNINITIALIZED;
-
-   cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
+   cs->bcs = kmalloc_array(channels, sizeof(*cs->bcs), GFP_KERNEL);
cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
if (!cs->bcs || !cs->inbuf) {
pr_err("out of memory\n");
@@ -1089,8 +1088,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, 
unsigned minors,
drv->ops = ops;
drv->owner = owner;
INIT_LIST_HEAD(>list);
-
-   drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
+   drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
if (!drv->cs)
goto error;
 
-- 
2.10.0



[PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions

2016-09-26 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 25 Sep 2016 22:22:04 +0200

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/isdn/gigaset/common.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 7c78144..cecbb6a 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver 
*drv, int channels,
 
cs->mode = M_UNKNOWN;
cs->mstate = MS_UNINITIALIZED;
-
-   cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
+   cs->bcs = kmalloc_array(channels, sizeof(*cs->bcs), GFP_KERNEL);
cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
if (!cs->bcs || !cs->inbuf) {
pr_err("out of memory\n");
@@ -1089,8 +1088,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, 
unsigned minors,
drv->ops = ops;
drv->owner = owner;
INIT_LIST_HEAD(>list);
-
-   drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
+   drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
if (!drv->cs)
goto error;
 
-- 
2.10.0