From patchwork Sat Jan 28 13:46:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 49862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1355192wrn; Sat, 28 Jan 2023 06:07:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXttknvEXWrbyVurZwLZlGdh+J8gEBQbUkmNViKMFCTcp06PemncxzZVzWqKCxQcIu9x5r+x X-Received: by 2002:a05:6402:1f87:b0:49d:9dd6:862f with SMTP id c7-20020a0564021f8700b0049d9dd6862fmr49849666edc.33.1674914855356; Sat, 28 Jan 2023 06:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674914855; cv=none; d=google.com; s=arc-20160816; b=q6QSB7qNXYptKk4v48XpbYCxxz0OsEK10JvoIXgQZHNX2dgAmUoT1BpUMbjemF2Mba ZLccciYQu+h9FU3xnK0Gf10hAFEfeM2uYa4JdvIZXqOqv+4+sdwXr+wkW6zb+Inesu4y zOBITCvsu8CQ/oGDpYyQwy9T1aDuQBspvCopTjeVhhZWeMCdSFzWm3O6p8pdiQGP/aAv UdFOf5ITTSrY4CrOqeYQjG9SToVzTm9sgPTsL2gdKIH4nllTqmpyb22A+qJ4WSusT6GP fKXluDt8gkB2YJWd2iFRzQ2ct0+aXuvAIUWDMQbZbfZcmdWdaKVZ54SdZU39vR8nItCt zang== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=13C64zCc0WR4YYBCJlsnzIHzIns8YeFrX386znr9n7g=; b=KMU+6yt7ZHfDuaU3lyuM/CHDivNl6OPZOxHX/pTYfJm7ii9UpfQ0ftl9A94pzWVsv8 4OjZJ8kfadUr8tFwPgNq3iQBNLakgJXLb3xULjNTfSnrl0TdzTlkoPKInswAKIMpaqaS pQHKJLCV/ry7/FayB1CCIqNK0EcknRdqsq8BPxLaTp3G1z5ygibPxrBbsQ2ZbYKhefhG fg6osANxSBINytBsu1RpoHJsJxZG/8JyCG76IsI6cMJP+CoQWe1O0hKglUeFybtxLwnA KWhQySVbGBD+R2KJj0IkhqhpqRxFIh8CTPu6m+qGeI0iy2JNlMT+mhVruhU7IcMOAxh+ tqVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=gmJb4ZPT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a056402430f00b0048cb4ab0e23si10226408edc.295.2023.01.28.06.07.10; Sat, 28 Jan 2023 06:07:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=gmJb4ZPT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234570AbjA1NrV (ORCPT + 99 others); Sat, 28 Jan 2023 08:47:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234236AbjA1NrU (ORCPT ); Sat, 28 Jan 2023 08:47:20 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E767B2C67F; Sat, 28 Jan 2023 05:47:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1674913621; bh=gd5UWYqxyut4hFbuycUVp9wAsaqAqcJEe6vfKpfaam8=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=gmJb4ZPTz8TIq/N3zIiOh/kZW/AEttO7GI5GWgEAheoqEumfAvU4cAb1a8Dn+ZFpm BN1ZOUqGOJmsHBY58Q2hjJausL7s9xYnnmK6TF/qTH3ssmITFJZ+XC0nmnXit+dPnh K/f6z4cACCc2SonLcBsezz81CDcQxpKun4Mq7lH8= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sat, 28 Jan 2023 14:47:01 +0100 (CET) X-EA-Auth: oerXmIxjLYD8tGh7VgjiBI5PhYp9cA4egWTF4yfqqtZHb3UknEQUcIXNTiwvgFl8t/W+oXY3LGDKHaKs00E1GTEVe7G1yVsS Date: Sat, 28 Jan 2023 19:16:55 +0530 From: Deepak R Varma To: Don Brace , "James E.J. Bottomley" , "Martin K. Petersen" , storagedev@microchip.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] scsi: hpsa: Use min helper for comparison and assignment Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756275519095991733?= X-GMAIL-MSGID: =?utf-8?q?1756275519095991733?= 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 --- 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,