lkml.org 
[lkml]   [2021]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] scsi: virtio_scsi: Fix a NULL pointer dereference in virtscsi_rescan_hotunplug()
From
On 11/30/21 18:19, Zhou Qingyang wrote:
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -337,7 +337,11 @@ static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
> unsigned char scsi_cmd[MAX_COMMAND_SIZE];
> int result, inquiry_len, inq_result_len = 256;
> char *inq_result = kmalloc(inq_result_len, GFP_KERNEL);
> -
> + if (!inq_result) {
> + pr_err("%s:no enough memory for inq_result\n",
> + __func__);
> + return;
> + }
> shost_for_each_device(sdev, shost) {
> inquiry_len = sdev->inquiry_len ? sdev->inquiry_len : 36;
>

In practice this will never happen, since the kmalloc is very small, so
I think it's easier to just return early without a printk. On the other
hand, if the out-of-memory really could happen, this should be a
pr_err_ratelimited.

Paolo

\
 
 \ /
  Last update: 2021-11-30 18:36    [W:0.711 / U:0.876 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site