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

From: Paul Bolle
Date: Wed Sep 28 2016 - 07:37:47 EST


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 <elfring@xxxxxxxxxxxxxxxxxxxxx>

> --- 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(&drv->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