From: Ranjan Kumar <ranjan.kumar@broadcom.com>
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 <ranjan.kumar@broadcom.com>
Subject: [PATCH v2 1/6] mpi3mr: Creation of helper function
Date: Fri, 15 Dec 2023 02:28:55 +0530 [thread overview]
Message-ID: <20231214205900.270488-2-ranjan.kumar@broadcom.com> (raw)
In-Reply-To: <20231214205900.270488-1-ranjan.kumar@broadcom.com>
[-- Attachment #1: Type: text/plain, Size: 3562 bytes --]
Use of helper function to get controller and shost details.
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
---
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);
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]
next prev parent reply other threads:[~2023-12-14 21:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-14 20:58 [PATCH v2 0/6] mpi3mr: Support PCIe Error Recovery Ranjan Kumar
2023-12-14 20:58 ` Ranjan Kumar [this message]
2024-01-04 23:11 ` [PATCH v2 1/6] mpi3mr: Creation of helper function Bjorn Helgaas
2023-12-14 20:58 ` [PATCH v2 2/6] mpi3mr: Support PCIe Error Recovery callback handlers Ranjan Kumar
2024-01-04 23:49 ` Bjorn Helgaas
2023-12-14 20:58 ` [PATCH v2 3/6] mpi3mr: Prevent PCI writes from driver during PCI error recovery Ranjan Kumar
2024-01-05 3:20 ` Bjorn Helgaas
2023-12-14 20:58 ` [PATCH v2 4/6] mpi3mr: Improve Shutdown times when firmware has faulted Ranjan Kumar
2023-12-14 20:58 ` [PATCH v2 5/6] mpi3mr: Reset stop_bsgs flag post controller reset failure Ranjan Kumar
2023-12-14 20:59 ` [PATCH v2 6/6] mpi3mr: Update driver version to 8.6.1.0.50 Ranjan Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231214205900.270488-2-ranjan.kumar@broadcom.com \
--to=ranjan.kumar@broadcom.com \
--cc=chandrakanth.patil@broadcom.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=prayas.patel@broadcom.com \
--cc=rajsekhar.chundru@broadcom.com \
--cc=sathya.prakash@broadcom.com \
--cc=sumit.saxena@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox