From patchwork Thu Dec 14 20:58:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ranjan Kumar X-Patchwork-Id: 754765 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9BB72DF66 for ; Thu, 14 Dec 2023 21:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="W3uvO2FP" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6d267461249so584228b3a.3 for ; Thu, 14 Dec 2023 13:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1702587662; x=1703192462; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=MdLtQ6r57qyKuA0ogKBq5zfOsRV+jdFJgmY9lNl5pGk=; b=W3uvO2FP410N/DqoU/lUQCVwficRFnDD28lkfXtmqgDJ0YAbCSb+v8mutUdeanZcVc fA7h8cJ4d7Wg+KgedMxxza7eXe3oQMDfhHJKOZ9wYDWAt6kW712/W0ok3IAZib1PlvoV AjE5cebxmqvCz1EZfEMEEiuBYxSrBx2qfccrY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702587662; x=1703192462; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MdLtQ6r57qyKuA0ogKBq5zfOsRV+jdFJgmY9lNl5pGk=; b=BSIatwr0RzvHQyU/G/iVRvICRz7DEq5jz01iBwNLh3dnFeyq1W2B0V6jDh62oaYmYE 9AcfykYXRPwpfpv3oNvEdTguv1Td4WJ2tGtuIlx9+ujUNP9bKfqBSltEYqsBQX90QDab 9sAZgpTeHvIDg8O0twPyFmTvj/kFUW3TQ33RVSttB8KzLa2+joJ7vzg6+jOrKsxkTOzR 4vnJC2YZEIJ7AgtGX94Ogbrqlw0NyysBUdzotgpETBLmC5jDTWXehH++n3E3z1/VHuxD HR/bcmLsCJib7Lm9nU1x+DB7leZzG+MtSi4yXdy2rKvZm8AcYSPgbRmxY1rENSH9JCPT s48Q== X-Gm-Message-State: AOJu0Yx/N4WnfnkkLIad4LL825apkCCsj2uhA3xxOHAcNyPjOUyN/Aom b760EDskAJkCmXK/MKunRmMO8O+I6kYHfqZi2X131Cs724QBt6fRauGPKJ7EJmTdvkJSM6QyU/n l35ie3j4GAd1ngSCH0EB3ZT1f8zWHgDgA1xij2WV8qhProkzP8FSqWpvPh90AJGSGXB3UwD/ew6 JMzMd6PAOvOw== X-Google-Smtp-Source: AGHT+IE518HiBlXymt/MejxnVwizYC5xhHPpCrq5UH9/vVHGO01H7bTJu+IivEcNHPhZSKeoSNy4EA== X-Received: by 2002:a05:6a00:4601:b0:6cb:6a27:ab57 with SMTP id ko1-20020a056a00460100b006cb6a27ab57mr5686252pfb.14.1702587662002; Thu, 14 Dec 2023 13:01:02 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id bv190-20020a632ec7000000b005c2967852c5sm11904303pgb.30.2023.12.14.13.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:01:01 -0800 (PST) From: Ranjan Kumar To: linux-scsi@vger.kernel.org, martin.petersen@oracle.com Cc: rajsekhar.chundru@broadcom.com, sathya.prakash@broadcom.com, sumit.saxena@broadcom.com, chandrakanth.patil@broadcom.com, prayas.patel@broadcom.com, Ranjan Kumar Subject: [PATCH v2 1/6] mpi3mr: Creation of helper function Date: Fri, 15 Dec 2023 02:28:55 +0530 Message-Id: <20231214205900.270488-2-ranjan.kumar@broadcom.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231214205900.270488-1-ranjan.kumar@broadcom.com> References: <20231214205900.270488-1-ranjan.kumar@broadcom.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use of helper function to get controller and shost details. Signed-off-by: Sathya Prakash Signed-off-by: Ranjan Kumar --- drivers/scsi/mpi3mr/mpi3mr_os.c | 54 ++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 1bffd629c124..76ba31a9517d 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -5230,6 +5230,35 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id) return retval; } +/** + * mpi3mr_get_shost_and_mrioc - get shost and ioc reference if + * they are valid + * @pdev: PCI device struct + * @shost: address to store scsi host reference + * @mrioc: address store HBA adapter reference + * + * Return: 0 if *shost and *ioc are not NULL otherwise -1. + */ + +static int +mpi3mr_get_shost_and_mrioc(struct pci_dev *pdev, + struct Scsi_Host **shost, struct mpi3mr_ioc **mrioc) +{ + *shost = pci_get_drvdata(pdev); + if (*shost == NULL) { + dev_err(&pdev->dev, "pdev's driver data is null\n"); + return -ENXIO; + } + + *mrioc = shost_priv(*shost); + if (*mrioc == NULL) { + dev_err(&pdev->dev, "shost's private data is null\n"); + *shost = NULL; + return -ENXIO; + } + return 0; +} + /** * mpi3mr_remove - PCI remove callback * @pdev: PCI device instance @@ -5242,7 +5271,7 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id) */ static void mpi3mr_remove(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; struct workqueue_struct *wq; unsigned long flags; @@ -5250,7 +5279,7 @@ static void mpi3mr_remove(struct pci_dev *pdev) struct mpi3mr_hba_port *port, *hba_port_next; struct mpi3mr_sas_node *sas_expander, *sas_expander_next; - if (!shost) + if (mpi3mr_get_shost_and_mrioc(pdev, &shost, &mrioc)) return; mrioc = shost_priv(shost); @@ -5328,12 +5357,12 @@ static void mpi3mr_remove(struct pci_dev *pdev) */ static void mpi3mr_shutdown(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; struct workqueue_struct *wq; unsigned long flags; - if (!shost) + if (mpi3mr_get_shost_and_mrioc(pdev, &shost, &mrioc)) return; mrioc = shost_priv(shost); @@ -5361,17 +5390,19 @@ static void mpi3mr_shutdown(struct pci_dev *pdev) * Change the power state to the given value and cleanup the IOC * by issuing MUR and shutdown notification * - * Return: 0 always. + * Return: 0 on success, non-zero on failure */ static int __maybe_unused mpi3mr_suspend(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); - struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; + int rc; - if (!shost) - return 0; + rc = mpi3mr_get_shost_and_mrioc(pdev, &shost, &mrioc); + if (rc) + return rc; mrioc = shost_priv(shost); while (mrioc->reset_in_progress || mrioc->is_driver_loading) @@ -5402,13 +5433,14 @@ static int __maybe_unused mpi3mr_resume(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); - struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; pci_power_t device_state = pdev->current_state; int r; - if (!shost) - return 0; + r = mpi3mr_get_shost_and_mrioc(pdev, &shost, &mrioc); + if (r) + return r; mrioc = shost_priv(shost);