linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: hpsa: Use min helper for comparison and assignment
@ 2023-01-28 13:46 Deepak R Varma
  0 siblings, 0 replies; only message in thread
From: Deepak R Varma @ 2023-01-28 13:46 UTC (permalink / raw)
  To: Don Brace, James E.J. Bottomley, Martin K. Petersen, storagedev,
	linux-scsi, linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar, Deepak R Varma

Simplify code by using min_t() helper macro for logical evaluation
and value assignment. Use the _t variant macro since the variable
types are not same.
Proposed change is identified using minmax.cocci semantic patch script.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/scsi/hpsa.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index c74fec4c2bd6..e030d07c4341 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2665,12 +2665,10 @@ static void complete_scsi_command(struct CommandList *cp)
 	case CMD_TARGET_STATUS:
 		cmd->result |= ei->ScsiStatus;
 		/* copy the sense data */
-		if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo))
-			sense_data_size = SCSI_SENSE_BUFFERSIZE;
-		else
-			sense_data_size = sizeof(ei->SenseInfo);
+		sense_data_size = min_t(size_t, SCSI_SENSE_BUFFERSIZE, sizeof(ei->SenseInfo));
 		if (ei->SenseLen < sense_data_size)
 			sense_data_size = ei->SenseLen;
+
 		memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size);
 		if (ei->ScsiStatus)
 			decode_sense_data(ei->SenseInfo, sense_data_size,
@@ -3630,11 +3628,9 @@ static bool hpsa_vpd_page_supported(struct ctlr_info *h,
 				buf, HPSA_VPD_HEADER_SZ);
 	if (rc != 0)
 		goto exit_unsupported;
+
 	pages = buf[3];
-	if ((pages + HPSA_VPD_HEADER_SZ) <= 255)
-		bufsize = pages + HPSA_VPD_HEADER_SZ;
-	else
-		bufsize = 255;
+	bufsize = min_t(uint, (pages + HPSA_VPD_HEADER_SZ), 255);
 
 	/* Get the whole VPD page list */
 	rc = hpsa_scsi_do_inquiry(h, scsi3addr,
-- 
2.34.1




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-28 13:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-28 13:46 [PATCH] scsi: hpsa: Use min helper for comparison and assignment Deepak R Varma

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).