mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 20:23:57 +08:00
cifs: misc: Use array_size() in if-statement controlling expression
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> Signed-off-by: Steve French <stfrench@microsoft.com> Reviewed-by: Aurelien Aptel <aaptel@suse.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
parent
5618303d85
commit
bf1028a41e
@ -844,28 +844,26 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
|
|||||||
struct bio_vec *bv = NULL;
|
struct bio_vec *bv = NULL;
|
||||||
|
|
||||||
if (iov_iter_is_kvec(iter)) {
|
if (iov_iter_is_kvec(iter)) {
|
||||||
memcpy(&ctx->iter, iter, sizeof(struct iov_iter));
|
memcpy(&ctx->iter, iter, sizeof(*iter));
|
||||||
ctx->len = count;
|
ctx->len = count;
|
||||||
iov_iter_advance(iter, count);
|
iov_iter_advance(iter, count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_pages * sizeof(struct bio_vec) <= CIFS_AIO_KMALLOC_LIMIT)
|
if (array_size(max_pages, sizeof(*bv)) <= CIFS_AIO_KMALLOC_LIMIT)
|
||||||
bv = kmalloc_array(max_pages, sizeof(struct bio_vec),
|
bv = kmalloc_array(max_pages, sizeof(*bv), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
|
|
||||||
if (!bv) {
|
if (!bv) {
|
||||||
bv = vmalloc(array_size(max_pages, sizeof(struct bio_vec)));
|
bv = vmalloc(array_size(max_pages, sizeof(*bv)));
|
||||||
if (!bv)
|
if (!bv)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_pages * sizeof(struct page *) <= CIFS_AIO_KMALLOC_LIMIT)
|
if (array_size(max_pages, sizeof(*pages)) <= CIFS_AIO_KMALLOC_LIMIT)
|
||||||
pages = kmalloc_array(max_pages, sizeof(struct page *),
|
pages = kmalloc_array(max_pages, sizeof(*pages), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
|
|
||||||
if (!pages) {
|
if (!pages) {
|
||||||
pages = vmalloc(array_size(max_pages, sizeof(struct page *)));
|
pages = vmalloc(array_size(max_pages, sizeof(*pages)));
|
||||||
if (!pages) {
|
if (!pages) {
|
||||||
kvfree(bv);
|
kvfree(bv);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
Loading…
Reference in New Issue
Block a user