Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp463517pxb; Wed, 8 Sep 2021 05:23:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB6hFDtBn9OQnWj/InKg8mqDQJ5M9K8W/1pGc1MY+iczeoTpPsO5nCvnL3ReqsJZtVhoX9 X-Received: by 2002:a6b:2b43:: with SMTP id r64mr2975306ior.187.1631103786028; Wed, 08 Sep 2021 05:23:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631103786; cv=none; d=google.com; s=arc-20160816; b=eeJbvmTMDRDG4Jjgz+ZqHXyYuUyt6suRrkxzIhdy1Zemw2bC7yR5xRdV5oF43oqh8F 8oGvLZTawDFipfk0hbbJUm38UX4udraL0wYWx8EW80ey69kBqxdXhiCBbKte8rLQMska 8zCFI2xFLx5y8bu8mqMBsTTCU2+8Z8wGwWzARLGpGxLrHLzi1zepNYFoRsIpMMzyzJUZ ocxOEYMHgiegPOh0bKiIQ3X6gKgtxasV3zwVdIA3DdO3yY3ibMR0EkCGZogmOuzsbrAE zmfdp9y3Eg2H6GvUzQRqcEAHYMU826CyjT3t/sIvglwKZdf0xT4lLjadh6iBjROYdf3z TUNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=a4AF4q0MINREtkgOR+fIaVvpppEmXRJTzk54cTMoeSU=; b=DO766zG5cn7IQNEKqOyF+fgdWUi13Ciu2VXmelgagBjDE0oDZ485WZFGzvnOz8aQQ1 bcA6bSlCxLeMJ1GoxTDP1t6llutfZF0jSK2MId8W5g0KNrmgYrcDCoELzTjSEEPI5Iwr vgBfrlz27+G0eWw9Ses57VnoGc4mFOKkMjafeO4BWv6rNOJPaXG9obGDww0NrvzP4ybq hE7dPHXQUGXYs/gQoBQqXwUEgLNmNg5Q+7r4hR4ADABR0OqUiniXI2tt2gg+wGXWOcgy sR+zHpFgaQgVR/8Qy/va06wbjqRyX3nu3tvYjm4w4eenUjr6gu9kYCEyRyDyWZw2y2VX aNAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si1767113ioa.54.2021.09.08.05.22.38; Wed, 08 Sep 2021 05:23:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348875AbhIHKaG (ORCPT + 99 others); Wed, 8 Sep 2021 06:30:06 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:15251 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbhIHKaF (ORCPT ); Wed, 8 Sep 2021 06:30:05 -0400 Received: from dggeml765-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H4JHm2JMhz1DGpG; Wed, 8 Sep 2021 18:28:04 +0800 (CST) Received: from huawei.com (10.175.124.27) by dggeml765-chm.china.huawei.com (10.1.199.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 8 Sep 2021 18:28:55 +0800 From: Liu Yuntao To: , , CC: , , , , Subject: [PATCH] virtio-gpu: fix possible memory allocation failure Date: Wed, 8 Sep 2021 18:26:47 +0800 Message-ID: <20210908102648.2326917-1-liuyuntao10@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeml765-chm.china.huawei.com (10.1.199.175) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When kmem_cache_zalloc in virtio_gpu_get_vbuf fails, it will return an error code. But none of its callers checks this error code, and a core dump will take place. Considering many of its callers can't handle such error, I add a __GFP_NOFAIL flag when calling kmem_cache_zalloc to make sure it won't fail, and delete those unused error handlings. Fixes: dc5698e80cf724 ("Add virtio gpu driver.") Signed-off-by: Yuntao Liu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index cf84d382dd41..5286cf110208 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -91,9 +91,7 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev, { struct virtio_gpu_vbuffer *vbuf; - vbuf = kmem_cache_zalloc(vgdev->vbufs, GFP_KERNEL); - if (!vbuf) - return ERR_PTR(-ENOMEM); + vbuf = kmem_cache_zalloc(vgdev->vbufs, GFP_KERNEL | __GFP_NOFAIL); BUG_ON(size > MAX_INLINE_CMD_SIZE || size < sizeof(struct virtio_gpu_ctrl_hdr)); @@ -147,10 +145,6 @@ static void *virtio_gpu_alloc_cmd_resp(struct virtio_gpu_device *vgdev, vbuf = virtio_gpu_get_vbuf(vgdev, cmd_size, resp_size, resp_buf, cb); - if (IS_ERR(vbuf)) { - *vbuffer_p = NULL; - return ERR_CAST(vbuf); - } *vbuffer_p = vbuf; return (struct virtio_gpu_command *)vbuf->buf; } -- 2.23.0