From patchwork Wed Dec 14 03:21:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 634142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D57B2C4332F for ; Wed, 14 Dec 2022 03:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236968AbiLND3C (ORCPT ); Tue, 13 Dec 2022 22:29:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236844AbiLND27 (ORCPT ); Tue, 13 Dec 2022 22:28:59 -0500 X-Greylist: delayed 418 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 13 Dec 2022 19:28:58 PST Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4F2F222A3 for ; Tue, 13 Dec 2022 19:28:58 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-03 (Coremail) with SMTP id rQCowABXX5dTQZljo1eqBg--.32359S2; Wed, 14 Dec 2022 11:21:55 +0800 (CST) From: Jiasheng Jiang To: aacraid@microsemi.com, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] scsi: ips: Add missing check for dma_alloc_coherent Date: Wed, 14 Dec 2022 11:21:54 +0800 Message-Id: <20221214032154.41665-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: rQCowABXX5dTQZljo1eqBg--.32359S2 X-Coremail-Antispam: 1UD129KBjvd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Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add check for the return value of the dma_alloc_coherent in order to avoid NULL pointer dereference. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jiasheng Jiang --- drivers/scsi/ips.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c index 16419aeec02d..26101f5b0434 100644 --- a/drivers/scsi/ips.c +++ b/drivers/scsi/ips.c @@ -6932,6 +6932,11 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr) if(ips_cd_boot && !ips_FlashData){ ips_FlashData = dma_alloc_coherent(&pci_dev->dev, PAGE_SIZE << 7, &ips_flashbusaddr, GFP_KERNEL); + if (!ips_FlashData) { + IPS_PRINTK(KERN_WARNING, pci_dev, + "Unable to allocate ips FlashData structure\n"); + return ips_abort_init(ha, index); + } } ha->enq = dma_alloc_coherent(&pci_dev->dev, sizeof (IPS_ENQ),