Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1492742
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions |
| Date | 2016-09-28 18:50 +0200 |
| Message-ID | <smqds-Mt-15@gated-at.bofh.it> (permalink) |
| References | <qEuGl-43C-5@gated-at.bofh.it> <slGaB-5yk-1@gated-at.bofh.it> <slGaC-5yk-25@gated-at.bofh.it> <smlnr-63p-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
>> * 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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/5] ISDN-Gigaset: Fine-tuning for three function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:40 +0200
[PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:40 +0200
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions Paul Bolle <pebolle@tiscali.nl> - 2016-09-28 13:40 +0200
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-28 18:50 +0200
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions Paul Bolle <pebolle@tiscali.nl> - 2016-09-28 19:50 +0200
[PATCH 2/5] ISDN-Gigaset: Improve another size determination in gigaset_initcs() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:50 +0200
[PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:50 +0200
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Paul Bolle <pebolle@tiscali.nl> - 2016-09-26 23:20 +0200
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 07:30 +0200
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Paul Bolle <pebolle@tiscali.nl> - 2016-09-27 10:50 +0200
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 11:40 +0200
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Paul Bolle <pebolle@tiscali.nl> - 2016-09-27 11:50 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Tilman Schmidt <tilman@imap.cc> - 2016-09-27 12:30 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 13:40 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Tilman Schmidt <tilman@imap.cc> - 2016-09-27 14:10 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure isdn@linux-pingi.de - 2016-09-27 14:20 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 15:00 +0200
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Tilman Schmidt <tilman@imap.cc> - 2016-09-27 16:40 +0200
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-27 09:40 +0200
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 17:20 +0200
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-27 09:20 +0200
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 09:30 +0200
[PATCH 3/5] ISDN-Gigaset: Delete an error message for a failed memory allocation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:50 +0200
Re: [PATCH 3/5] ISDN-Gigaset: Delete an error message for a failed memory allocation Tilman Schmidt <tilman@imap.cc> - 2016-09-27 13:00 +0200
Re: [PATCH 3/5] ISDN-Gigaset: Delete an error message for a failed memory allocation Paul Bolle <pebolle@tiscali.nl> - 2016-09-28 13:50 +0200
[PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 17:50 +0200
RE: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses David Laight <David.Laight@ACULAB.COM> - 2016-09-26 18:10 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Joe Perches <joe@perches.com> - 2016-09-26 18:30 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 18:50 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Julia Lawall <julia.lawall@lip6.fr> - 2016-09-26 19:00 +0200
[PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 19:50 +0200
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Paul Bolle <pebolle@tiscali.nl> - 2016-09-26 20:40 +0200
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 20:50 +0200
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses David Miller <davem@davemloft.net> - 2016-09-27 02:20 +0200
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 07:40 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-09-26 19:40 +0200
Re: ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-26 20:10 +0200
Re: ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Paul Bolle <pebolle@tiscali.nl> - 2016-09-26 20:40 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-27 09:10 +0200
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-27 09:30 +0200
Re: [PATCH 0/5] ISDN-Gigaset: Fine-tuning for three function implementations Paul Bolle <pebolle@tiscali.nl> - 2016-09-26 22:40 +0200
Re: ISDN-Gigaset: Fine-tuning for three function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 07:20 +0200
Re: [PATCH 0/5] ISDN-Gigaset: Fine-tuning for three function implementations Paul Bolle <pebolle@tiscali.nl> - 2016-09-28 14:00 +0200
Re: ISDN-Gigaset: Fine-tuning for three function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-28 19:00 +0200
Re: ISDN-Gigaset: Fine-tuning for three function implementations Paul Bolle <pebolle@tiscali.nl> - 2016-09-28 20:00 +0200
csiph-web