From mboxrd@z Thu Jan 1 00:00:00 1970 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 23368C433EF for ; Tue, 7 Jun 2022 18:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350384AbiFGSYd (ORCPT ); Tue, 7 Jun 2022 14:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352220AbiFGSQ6 (ORCPT ); Tue, 7 Jun 2022 14:16:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43333CFD6; Tue, 7 Jun 2022 10:51:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 84DA6B8234C; Tue, 7 Jun 2022 17:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30D32C3411C; Tue, 7 Jun 2022 17:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654624268; bh=1NDrccUNSF/6uv2W+MpiyQ8aIC7EHlmxH2OYdzZod1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V8ALIV7kDmNHZn0GgOJ+i9yYnJKtfa+sjl8Mdn15CVzRovL5R8qpw6dYfR1jhhN6R iE7SBOsAb5lKyQp3Izi49K47Sw8TpMcyzVuKOsSkiam+lbbFB/FZFAEtG/scKSAR8u Sm8rmJfj7jwCyXe0K1KWg8aDxzCiJdvs8bQmEfpYGpPponuzoQCcAoyoOUUkBfV1qP b+YIrCYdBQy7kqfErBGqriE+amzc1NHJwH1i0aBI9CsH/EESnsOnmtSNl4p0kn2R+z +22mvvTcbCuVbiUWiIGrttG9C4ai5gUxGCNIaewQ1TOijJIxWXDB2BZsusNymlCqKe BoQE5u83rXu9w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hannes Reinecke , Zheyu Ma , "Martin K . Petersen" , Sasha Levin , hare@kernel.org, jejb@linux.ibm.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.18 38/68] scsi: myrb: Fix up null pointer access on myrb_cleanup() Date: Tue, 7 Jun 2022 13:48:04 -0400 Message-Id: <20220607174846.477972-38-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220607174846.477972-1-sashal@kernel.org> References: <20220607174846.477972-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hannes Reinecke [ Upstream commit f9f0a46141e2e39bedb4779c88380d1b5f018c14 ] When myrb_probe() fails the callback might not be set, so we need to validate the 'disable_intr' callback in myrb_cleanup() to not cause a null pointer exception. And while at it do not call myrb_cleanup() if we cannot enable the PCI device at all. Link: https://lore.kernel.org/r/20220523120244.99515-1-hare@suse.de Reported-by: Zheyu Ma Tested-by: Zheyu Ma Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/myrb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c index 71585528e8db..e885c1dbf61f 100644 --- a/drivers/scsi/myrb.c +++ b/drivers/scsi/myrb.c @@ -1239,7 +1239,8 @@ static void myrb_cleanup(struct myrb_hba *cb) myrb_unmap(cb); if (cb->mmio_base) { - cb->disable_intr(cb->io_base); + if (cb->disable_intr) + cb->disable_intr(cb->io_base); iounmap(cb->mmio_base); } if (cb->irq) @@ -3413,9 +3414,13 @@ static struct myrb_hba *myrb_detect(struct pci_dev *pdev, mutex_init(&cb->dcmd_mutex); mutex_init(&cb->dma_mutex); cb->pdev = pdev; + cb->host = shost; - if (pci_enable_device(pdev)) - goto failure; + if (pci_enable_device(pdev)) { + dev_err(&pdev->dev, "Failed to enable PCI device\n"); + scsi_host_put(shost); + return NULL; + } if (privdata->hw_init == DAC960_PD_hw_init || privdata->hw_init == DAC960_P_hw_init) { -- 2.35.1