* [PATCH] cifs: misc: Use array_size() in if-statement controlling expression
@ 2020-06-15 22:41 Gustavo A. R. Silva
2020-06-16 11:17 ` Aurélien Aptel
2020-06-16 18:43 ` Kees Cook
0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-15 22:41 UTC (permalink / raw)
To: Steve French
Cc: linux-cifs, samba-technical, linux-kernel, Gustavo A. R. Silva,
Kees Cook
Use array_size() instead of the open-coded version in the controlling
expression of the if statement.
Also, while there, use the preferred form for passing a size of a struct.
The alternative form where struct name is spelled out hurts readability
and introduces an opportunity for a bug when the pointer variable type is
changed but the corresponding sizeof that is passed as argument is not.
This issue was found with the help of Coccinelle and, audited and fixed
manually.
Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
fs/cifs/misc.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 56791a692c8b..e44d049142d0 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -844,28 +844,26 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
struct bio_vec *bv = NULL;
if (iov_iter_is_kvec(iter)) {
- memcpy(&ctx->iter, iter, sizeof(struct iov_iter));
+ memcpy(&ctx->iter, iter, sizeof(*iter));
ctx->len = count;
iov_iter_advance(iter, count);
return 0;
}
- if (max_pages * sizeof(struct bio_vec) <= CIFS_AIO_KMALLOC_LIMIT)
- bv = kmalloc_array(max_pages, sizeof(struct bio_vec),
- GFP_KERNEL);
+ if (array_size(max_pages, sizeof(*bv)) <= CIFS_AIO_KMALLOC_LIMIT)
+ bv = kmalloc_array(max_pages, sizeof(*bv), GFP_KERNEL);
if (!bv) {
- bv = vmalloc(array_size(max_pages, sizeof(struct bio_vec)));
+ bv = vmalloc(array_size(max_pages, sizeof(*bv)));
if (!bv)
return -ENOMEM;
}
- if (max_pages * sizeof(struct page *) <= CIFS_AIO_KMALLOC_LIMIT)
- pages = kmalloc_array(max_pages, sizeof(struct page *),
- GFP_KERNEL);
+ if (array_size(max_pages, sizeof(*pages)) <= CIFS_AIO_KMALLOC_LIMIT)
+ pages = kmalloc_array(max_pages, sizeof(*pages), GFP_KERNEL);
if (!pages) {
- pages = vmalloc(array_size(max_pages, sizeof(struct page *)));
+ pages = vmalloc(array_size(max_pages, sizeof(*pages)));
if (!pages) {
kvfree(bv);
return -ENOMEM;
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: misc: Use array_size() in if-statement controlling expression
2020-06-15 22:41 [PATCH] cifs: misc: Use array_size() in if-statement controlling expression Gustavo A. R. Silva
@ 2020-06-16 11:17 ` Aurélien Aptel
2020-06-16 19:35 ` Steve French
2020-06-16 18:43 ` Kees Cook
1 sibling, 1 reply; 4+ messages in thread
From: Aurélien Aptel @ 2020-06-16 11:17 UTC (permalink / raw)
To: Gustavo A. R. Silva, Steve French
Cc: linux-cifs, samba-technical, linux-kernel, Gustavo A. R. Silva,
Kees Cook
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
Cheers,
--
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: misc: Use array_size() in if-statement controlling expression
2020-06-15 22:41 [PATCH] cifs: misc: Use array_size() in if-statement controlling expression Gustavo A. R. Silva
2020-06-16 11:17 ` Aurélien Aptel
@ 2020-06-16 18:43 ` Kees Cook
1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2020-06-16 18:43 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Steve French, linux-cifs, samba-technical, linux-kernel,
Gustavo A. R. Silva
On Mon, Jun 15, 2020 at 05:41:12PM -0500, Gustavo A. R. Silva wrote:
> Use array_size() instead of the open-coded version in the controlling
> expression of the if statement.
>
> Also, while there, use the preferred form for passing a size of a struct.
> The alternative form where struct name is spelled out hurts readability
> and introduces an opportunity for a bug when the pointer variable type is
> changed but the corresponding sizeof that is passed as argument is not.
>
> This issue was found with the help of Coccinelle and, audited and fixed
> manually.
>
> Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cifs: misc: Use array_size() in if-statement controlling expression
2020-06-16 11:17 ` Aurélien Aptel
@ 2020-06-16 19:35 ` Steve French
0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2020-06-16 19:35 UTC (permalink / raw)
To: Aurélien Aptel
Cc: Gustavo A. R. Silva, Steve French, CIFS, samba-technical, LKML,
Kees Cook, Gustavo A. R. Silva
Added the two reviewed-bys and merged into cifs-2.6.git for-next
On Tue, Jun 16, 2020 at 6:17 AM Aurélien Aptel via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> Reviewed-by: Aurelien Aptel <aaptel@suse.com>
>
> Cheers,
> --
> Aurélien Aptel / SUSE Labs Samba Team
> GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3
> SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
> GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-16 19:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 22:41 [PATCH] cifs: misc: Use array_size() in if-statement controlling expression Gustavo A. R. Silva
2020-06-16 11:17 ` Aurélien Aptel
2020-06-16 19:35 ` Steve French
2020-06-16 18:43 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).