* [PATCH v1] bcache: Check for NULL return of kzalloc()
@ 2022-03-24 9:27 QintaoShen
2022-04-07 16:59 ` Coly Li
0 siblings, 1 reply; 2+ messages in thread
From: QintaoShen @ 2022-03-24 9:27 UTC (permalink / raw)
To: colyli; +Cc: linux-bcache, kent.overstreet, linux-kernel, QintaoShen
kzalloc() is a memory allocation function which may return a NULL pointer.
Therefore, it is better to check the return value of kzalloc() to avoid potential
NULL-pointer dereference.
Signed-off-by: QintaoShen <unSimple1993@163.com>
---
drivers/md/bcache/request.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index fdd0194..232ffe3 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -1105,6 +1105,9 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
* which would call closure_get(&dc->disk.cl)
*/
ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
+ if (!ddpp)
+ return ;
+
ddip->d = d;
/* Count on the bcache device */
ddip->orig_bdev = orig_bdev;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] bcache: Check for NULL return of kzalloc()
2022-03-24 9:27 [PATCH v1] bcache: Check for NULL return of kzalloc() QintaoShen
@ 2022-04-07 16:59 ` Coly Li
0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2022-04-07 16:59 UTC (permalink / raw)
To: QintaoShen; +Cc: linux-bcache, kent.overstreet, linux-kernel
On 3/24/22 5:27 PM, QintaoShen wrote:
> kzalloc() is a memory allocation function which may return a NULL pointer.
> Therefore, it is better to check the return value of kzalloc() to avoid potential
> NULL-pointer dereference.
>
> Signed-off-by: QintaoShen <unSimple1993@163.com>
> ---
> drivers/md/bcache/request.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
> index fdd0194..232ffe3 100644
> --- a/drivers/md/bcache/request.c
> +++ b/drivers/md/bcache/request.c
> @@ -1105,6 +1105,9 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
> * which would call closure_get(&dc->disk.cl)
> */
> ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
> + if (!ddpp)
> + return ;
This is wrong. If you test your patch, you may experience a system hang
I guess.
Coly Li
> +
> ddip->d = d;
> /* Count on the bcache device */
> ddip->orig_bdev = orig_bdev;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-07 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 9:27 [PATCH v1] bcache: Check for NULL return of kzalloc() QintaoShen
2022-04-07 16:59 ` Coly Li
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).