From patchwork Sat Jan 28 07:58:48 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: 49812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1241495wrn; Sat, 28 Jan 2023 00:08:41 -0800 (PST) X-Google-Smtp-Source: AK7set/z5GMeeVTT/GMmd5bR1ZL81QVL2IXS6Y78jyZGmEcY256jWcekSo/8UX0b3/AtTgwOskWP X-Received: by 2002:a17:907:6d8b:b0:879:d438:4d1c with SMTP id sb11-20020a1709076d8b00b00879d4384d1cmr9186142ejc.21.1674893321183; Sat, 28 Jan 2023 00:08:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674893321; cv=none; d=google.com; s=arc-20160816; b=A/431qMTBhUoYuxvE5OSY+lgGJRtsC1FeCofc9evB0Q3/wtrCQ7gCPGBJI5k7S/bSv iEpdsgFvrGgFVLCIQm53FBH2j1qYfbrSIKRrhg4mb0qe1d4vmMjCczPWo8/ONSHZx0L8 k82vdEfVoRlCJvtm1kczq7taXBcw38iyY1RiEbdHXqGAUiFwNksSUJAR2LIDmJEfBZSo WoF82QWItBDUPi9ciNeY3UVTab9e8XAd4VRTwUOGK9Fnt8QG91lNrJ7I+P4uCUJ1fiCY MyUyuRJi8/j7eJLv5/3S8vbJrVmq5fQ1Do4bmBKFJ4VvFTqvIBnTJfztWRHwXlkidGiD JM4w== 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=9CqNu7KKk/DL5HEKRPWde8Eg4B8JLtbBnUsz5i72He8=; b=k/FUBkGudrmTM95eucBN2/WCTVoH2Ysa/zt5B+Kz0E+DU9iO/Vln+VB0zk0IUbgoIk X7qkYojNAdAR20l53tkcojp3SE63MahZlMqNEdCyOznhSiKT6YDgcxHgMZH+hyGcnYTd Argzvs7ejQTiSgsRYPNiBmjSS49U6PHQxigkohmb4nDKasPrH4g3rURqTcx6waCffbNr Gs+diQ0oHRVM5mND01HagFNAuYoscyX9b1R7aNVbakfgASG/ze7eOJQwPsL7xD3cdL6c 1q+n5Ikkn8tYEJIqW21l6LP0RPVZBXbQOsosmPwKRZYi2QnU3sXLfmb2Y2KwGb35r5vz LcCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=J6mT4L4Z; 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 az7-20020a170907904700b00880c412040asi2426533ejc.358.2023.01.28.00.08.15; Sat, 28 Jan 2023 00:08:41 -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=J6mT4L4Z; 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 S233446AbjA1H7J (ORCPT + 99 others); Sat, 28 Jan 2023 02:59:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjA1H7I (ORCPT ); Sat, 28 Jan 2023 02:59:08 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B1824616D; Fri, 27 Jan 2023 23:59:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1674892733; bh=qMf+Xfzo+BufqPQ/JYYC7vZ8jwBEi6vlqKAvmk8x3H4=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=J6mT4L4ZQxGRbqR2dJy2cRxz+ACZgwokL5It6x0711QYr9Z39yyaEyLLK9dCssfmC zFoB7QcWXieSioe6yKEH4+AktJidBhk7sZxxQaKpJVODvhNMF5sy69KDcsp61LlrBE WAtzF2nT9HE1Jf6c8wmK3vLpOoS8B0aUty0i6Zgg= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sat, 28 Jan 2023 08:58:53 +0100 (CET) X-EA-Auth: AbVnrGizcFtzXuYqAw3Q9ExojJUsxcVdLH/fMIOfZgK/DtWWIjme5wpWUyT/MEz5Bt3cMParN9MS8TEqjwiWKARGs9R3Nu+I Date: Sat, 28 Jan 2023 13:28:48 +0530 From: Deepak R Varma To: Kai =?iso-8859-1?q?M=E4kisara?= , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] scsi: st: Use min/max helpers 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?1756252938665126044?= X-GMAIL-MSGID: =?utf-8?q?1756252938665126044?= Simplify code by using min_t helper macro for logical evaluation and value assignment. Use the _t variant of min macro since the variable types are not same. This issue is identified by coccicheck using the minmax.cocci file. Signed-off-by: Deepak R Varma --- Please note: Proposed change is only compile/build tested. drivers/scsi/st.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index b90a440e135d..38aa59cba110 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -1574,8 +1574,7 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf, if (!STbp->do_dio) { if (STp->block_size) - bufsize = STp->block_size > st_fixed_buffer_size ? - STp->block_size : st_fixed_buffer_size; + bufsize = max(STp->block_size, st_fixed_buffer_size); else { bufsize = count; /* Make sure that data from previous user is not leaked even if @@ -2186,8 +2185,7 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) STps->eof, STbp->buffer_bytes, (int)(count - total)); ) /* end DEB */ - transfer = STbp->buffer_bytes < count - total ? - STbp->buffer_bytes : count - total; + transfer = min_t(size_t, STbp->buffer_bytes, (count - total)); if (!do_dio) { i = from_buffer(STbp, buf, transfer); if (i) { @@ -3996,7 +3994,7 @@ static int append_to_buffer(const char __user *ubp, struct st_buffer * st_bp, in } for (; i < st_bp->frp_segs && do_count > 0; i++) { struct page *page = st_bp->reserved_pages[i]; - cnt = length - offset < do_count ? length - offset : do_count; + cnt = min((length - offset), do_count); res = copy_from_user(page_address(page) + offset, ubp, cnt); if (res) return (-EFAULT); @@ -4028,7 +4026,7 @@ static int from_buffer(struct st_buffer * st_bp, char __user *ubp, int do_count) } for (; i < st_bp->frp_segs && do_count > 0; i++) { struct page *page = st_bp->reserved_pages[i]; - cnt = length - offset < do_count ? length - offset : do_count; + cnt = min((length - offset), do_count); res = copy_to_user(ubp, page_address(page) + offset, cnt); if (res) return (-EFAULT);