linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Don Brace <don.brace@pmcs.com>
To: scott.teel@pmcs.com, Kevin.Barnett@pmcs.com,
	scott.benesh@pmcs.com, james.bottomley@parallels.com,
	hch@infradead.org, Justin.Lindley@pmcs.com, elliott@hpe.com
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH 07/21] hpsa: correct check for non-disk devices
Date: Sat, 24 Oct 2015 14:53:09 -0500	[thread overview]
Message-ID: <20151024195309.17127.32428.stgit@brunhilda> (raw)
In-Reply-To: <20151024193306.17127.7819.stgit@brunhilda>

The driver is using two MACROs which seemingly are looking in
the wrong location for the device_flags returned from
CISS_REPORT_PHYS. Both MACROs, NON_DISK_PHYS_DEV and
PHYS_IOACCEL, are using the pointer returned from figure_lunaddrbytes
which is the address of the LUN.lunid element in
the extended CISS_REPORT_PHYS.  But the MACROS are using offsets
beyond the range of the element (offset 17 of an 8 byte element).

These MACROs actually are looking at the correct location but
they fail static checker analysis. It also will not work
if any new elements are added to the extended LUN structure.

Change the code to use the structure elements directly
since this MACRO is only used in one location.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Scott Teel <scott.teel@pmcs.com>
Reviewed-by: Justin Lindley <justin.lindley@pmcs.com>
Reviewed-by: Kevin Barnett <kevin.barnett@pmcs.com>
Signed-off-by: Don Brace <don.brace@pmcs.com>
---
 drivers/scsi/hpsa.c     |   28 +++++++++++++++-------------
 drivers/scsi/hpsa_cmd.h |    2 --
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 0d08682..d42063d 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -3672,19 +3672,18 @@ static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position,
 /* get physical drive ioaccel handle and queue depth */
 static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h,
 		struct hpsa_scsi_dev_t *dev,
-		u8 *lunaddrbytes,
+		struct ReportExtendedLUNdata *rlep, int rle_index,
 		struct bmic_identify_physical_device *id_phys)
 {
 	int rc;
-	struct ext_report_lun_entry *rle =
-		(struct ext_report_lun_entry *) lunaddrbytes;
+	struct ext_report_lun_entry *rle = &rlep->LUN[rle_index];
 
 	dev->ioaccel_handle = rle->ioaccel_handle;
-	if (PHYS_IOACCEL(lunaddrbytes) && dev->ioaccel_handle)
+	if ((rle->device_flags & 0x08) && dev->ioaccel_handle)
 		dev->hba_ioaccel_enabled = 1;
 	memset(id_phys, 0, sizeof(*id_phys));
-	rc = hpsa_bmic_id_physical_device(h, lunaddrbytes,
-			GET_BMIC_DRIVE_NUMBER(lunaddrbytes), id_phys,
+	rc = hpsa_bmic_id_physical_device(h, &rle->lunid[0],
+			GET_BMIC_DRIVE_NUMBER(&rle->lunid[0]), id_phys,
 			sizeof(*id_phys));
 	if (!rc)
 		/* Reserve space for FW operations */
@@ -3700,11 +3699,12 @@ static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h,
 }
 
 static void hpsa_get_path_info(struct hpsa_scsi_dev_t *this_device,
-	u8 *lunaddrbytes,
+	struct ReportExtendedLUNdata *rlep, int rle_index,
 	struct bmic_identify_physical_device *id_phys)
 {
-	if (PHYS_IOACCEL(lunaddrbytes)
-		&& this_device->ioaccel_handle)
+	struct ext_report_lun_entry *rle = &rlep->LUN[rle_index];
+
+	if ((rle->device_flags & 0x08) && this_device->ioaccel_handle)
 		this_device->hba_ioaccel_enabled = 1;
 
 	memcpy(&this_device->active_path_index,
@@ -3804,6 +3804,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
 	for (i = 0; i < nphysicals + nlogicals + 1; i++) {
 		u8 *lunaddrbytes, is_OBDR = 0;
 		int rc = 0;
+		int phys_dev_index = i - (raid_ctlr_position == 0);
 
 		/* Figure out where the LUN ID info is coming from */
 		lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position,
@@ -3812,7 +3813,8 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
 		/* skip masked non-disk devices */
 		if (MASKED_DEVICE(lunaddrbytes))
 			if (i < nphysicals + (raid_ctlr_position == 0) &&
-				NON_DISK_PHYS_DEV(lunaddrbytes))
+				(physdev_list->
+				LUN[phys_dev_index].device_flags & 0x01))
 				continue;
 
 		/* Get device type, vendor, model, device id */
@@ -3877,9 +3879,9 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
 				/* Never use RAID mapper in HBA mode. */
 				this_device->offload_enabled = 0;
 				hpsa_get_ioaccel_drive_info(h, this_device,
-					lunaddrbytes, id_phys);
-				hpsa_get_path_info(this_device, lunaddrbytes,
-							id_phys);
+					physdev_list, phys_dev_index, id_phys);
+				hpsa_get_path_info(this_device,
+					physdev_list, phys_dev_index, id_phys);
 			}
 			ncurrent++;
 			break;
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index 47c756b..c2c0737 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -260,8 +260,6 @@ struct ext_report_lun_entry {
 	u8 wwid[8];
 	u8 device_type;
 	u8 device_flags;
-#define NON_DISK_PHYS_DEV(x) ((x)[17] & 0x01)
-#define PHYS_IOACCEL(x) ((x)[17] & 0x08)
 	u8 lun_count; /* multi-lun device, how many luns */
 	u8 redundant_paths;
 	u32 ioaccel_handle; /* ioaccel1 only uses lower 16 bits */


  parent reply	other threads:[~2015-10-24 19:56 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-24 19:52 [PATCH 00/21] hpsa updates Don Brace
2015-10-24 19:52 ` [PATCH 01/21] hpsa: correct calls to dev_printk Don Brace
2015-10-26 12:52   ` Tomas Henzl
2015-10-26 13:41     ` Don Brace
2015-10-24 19:52 ` [PATCH 02/21] hpsa: allow driver requested rescans Don Brace
2015-10-26 14:36   ` Tomas Henzl
2015-10-24 19:52 ` [PATCH 03/21] hpsa: abandon rescans on memory alloaction failures Don Brace
2015-10-26 14:24   ` Tomas Henzl
2015-10-26 14:29     ` Don Brace
2015-10-26 14:32       ` Tomas Henzl
2015-10-26 14:36         ` Tomas Henzl
2015-10-24 19:52 ` [PATCH 04/21] hpsa: correct transfer length for 6 byte read/write commands Don Brace
2015-10-26 14:37   ` Tomas Henzl
2015-10-24 19:52 ` [PATCH 05/21] hpsa: fix hpsa_adjust_hpsa_scsi_table Don Brace
2015-10-26 14:55   ` Tomas Henzl
2015-10-26 15:22     ` Don Brace
2015-10-24 19:53 ` [PATCH 06/21] hpsa: fix physical target reset Don Brace
2015-10-24 19:53 ` Don Brace [this message]
2015-10-24 19:53 ` [PATCH 08/21] hpsa: correct ioaccel2 sg chain len Don Brace
2015-10-24 19:53 ` [PATCH 09/21] hpsa: simplify check for device exposure Don Brace
2015-10-24 19:53 ` [PATCH 10/21] hpsa: simplify update scsi devices Don Brace
2015-10-24 19:53 ` [PATCH 11/21] hpsa: add function is_logical_device Don Brace
2015-10-24 19:53 ` [PATCH 12/21] hpsa: enhance hpsa_get_device_id Don Brace
2015-10-24 19:53 ` [PATCH 13/21] hpsa: refactor hpsa_figure_bus_target_lun Don Brace
2015-10-24 19:53 ` [PATCH 14/21] hpsa: move scsi_add_device and scsi_remove_device calls to new function Don Brace
2015-10-24 19:53 ` [PATCH 15/21] External array LUNs must use target and lun numbers assigned by the Don Brace
2015-10-24 19:54 ` [PATCH 16/21] hpsa: eliminate fake lun0 enclosures Don Brace
2015-10-24 19:54 ` [PATCH 17/21] hpsa: add discovery polling for PT RAID devices Don Brace
2015-10-24 19:54 ` [PATCH 18/21] hpsa: disable report lun data caching Don Brace
2015-10-24 19:54 ` [PATCH 19/21] hpsa: enhance device messages Don Brace
2015-10-24 20:19   ` kbuild test robot
2015-10-26 13:36     ` Don Brace
2015-10-24 19:54 ` [PATCH 20/21] hpsa: add in sas transport class Don Brace
2015-10-24 19:54 ` [PATCH 21/21] hpsa: bump the driver version Don Brace

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=20151024195309.17127.32428.stgit@brunhilda \
    --to=don.brace@pmcs.com \
    --cc=Justin.Lindley@pmcs.com \
    --cc=Kevin.Barnett@pmcs.com \
    --cc=elliott@hpe.com \
    --cc=hch@infradead.org \
    --cc=james.bottomley@parallels.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=scott.benesh@pmcs.com \
    --cc=scott.teel@pmcs.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;
as well as URLs for NNTP newsgroup(s).