Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3946615pxb; Mon, 1 Feb 2021 08:35:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY9sMe4arOrgmkXX5eCY7Og7VPyc68IfgkEXmjZKX7vG0H3dlJBALxbzndOwNOD8cPINlv X-Received: by 2002:a17:906:f24a:: with SMTP id gy10mr4628438ejb.531.1612197315955; Mon, 01 Feb 2021 08:35:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612197315; cv=none; d=google.com; s=arc-20160816; b=FiMrhWBAXOBf1hD1u9rTAKj45C0qKw/1jYw2jhEAfb4ziu7HJfgdW1e328h34GDYl1 dS0iEBkp99HNRkMxwQEvyUit3OXdc2uQCZ4O3McbWnTn2zp7ugwFMiKYvG91HAYmDtTK tyrO+sSqcq0pKD6CG9qOvKOLHoCW82/UCf16eU0dUQ/VpXZopmGWyBTPBQHqODGX1/hj pnKluxb93sMgV5coODoAlyYRf6wNViYjkBrfxbe777IoRDtaIl8DtpTRtKoMhdvuev5W XDY0rmXc7t4M1j8upo/sz5aNrhPqBtnzHJTQdpaYuudFhA0VLznFojlq4miT6s7v5dfZ D6sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=XkG/uJNlxoqQQQLU1vFXpL9Q/bX6mVtZEQ+8cQ5B8Xc=; b=ieau76ZChxXF1Xcl7sD7bPX7aelO9tPWAGyfQAi+M+X+SEJ39AnQ5ElRyy8+FPal3r t44nvTYQHiai3UT2kWk/LzB+tmpvy8q7WZzRoubZXgrYaEZ5uNQuOWPXM9oV2UAlUwRA NYs6dvlAToyogM4wmP8kMLR+B8Kn3ZMZAmyyAoEQ8qEX5vi9AdoyWZCak6dw2MvK8g/g WOsG3Jc93H93Yf/gaFhtRb64Vki2Ca6+VfA1Ks9KcVoHp1L5XKrK0CVF6FmUmvxs9bUc 5i+w5tshdstbcg+Bt5KdwMlmV1AQRtP1CQJ1ckC00cfLeGcRXiq2R0Td3cVkx5I65xV+ nyVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ayQxGiiq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re16si4447057ejb.93.2021.02.01.08.34.50; Mon, 01 Feb 2021 08:35:15 -0800 (PST) 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; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ayQxGiiq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbhBAQbo (ORCPT + 99 others); Mon, 1 Feb 2021 11:31:44 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:9170 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbhBAQ3o (ORCPT ); Mon, 1 Feb 2021 11:29:44 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Mon, 01 Feb 2021 08:29:04 -0800 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 1 Feb 2021 16:29:04 +0000 Received: from r-nvmx02.mtr.labs.mlnx (172.20.145.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Mon, 1 Feb 2021 16:28:59 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 6/9] vfio-pci/zdev: fix possible segmentation fault issue Date: Mon, 1 Feb 2021 16:28:25 +0000 Message-ID: <20210201162828.5938-7-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210201162828.5938-1-mgurtovoy@nvidia.com> References: <20210201162828.5938-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612196944; bh=XkG/uJNlxoqQQQLU1vFXpL9Q/bX6mVtZEQ+8cQ5B8Xc=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type; b=ayQxGiiqeenmoD/JrPn75P8r0BwmYVLMhD6tmP4L1HI2aaoedXroSJ20rVPg/SxBQ /Pt+IYuJchtXK2pQNeV7tH2iq9b7duqJMWVMF1sLH7wjByB/dTmNqGdk+s4Jn97T6W BmTvcZXfzd5DQR7oDa0P5BdEEvF+yq7b4j8z/BgTzGg6Yh8PI73zEsRsl4PHOwREGV 7gA2RN2hfOY0iNbRFTXAGbu9Lu4JTS+P2briir8/ZzkFaAnqg/Qk1HDXraDWP7JOKj 1aFG8IWlb8WDhAe3UCYKCaFNwshe47UfZYAjLGiSN8gx6IKs3WHH+E2Qb25XdDYFmH KodIoIKkFogEg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case allocation fails, we must behave correctly and exit with error. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci_zdev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_z= dev.c index 175096fcd902..e9ef4239ef7a 100644 --- a/drivers/vfio/pci/vfio_pci_zdev.c +++ b/drivers/vfio/pci/vfio_pci_zdev.c @@ -71,6 +71,8 @@ static int zpci_util_cap(struct zpci_dev *zdev, struct vf= io_info_cap *caps) int ret; =20 cap =3D kmalloc(cap_size, GFP_KERNEL); + if (!cap) + return -ENOMEM; =20 cap->header.id =3D VFIO_DEVICE_INFO_CAP_ZPCI_UTIL; cap->header.version =3D 1; @@ -94,6 +96,8 @@ static int zpci_pfip_cap(struct zpci_dev *zdev, struct vf= io_info_cap *caps) int ret; =20 cap =3D kmalloc(cap_size, GFP_KERNEL); + if (!cap) + return -ENOMEM; =20 cap->header.id =3D VFIO_DEVICE_INFO_CAP_ZPCI_PFIP; cap->header.version =3D 1; --=20 2.25.4