Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2165079pxy; Mon, 2 Aug 2021 22:16:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr3yWDSqAGDxtwJra5Jpj3Bv4M7QaUJOsn2KwarBkIir7A4URhA3fV/TIfUSJZQVNAhtyr X-Received: by 2002:a92:ce0e:: with SMTP id b14mr854280ilo.109.1627967782372; Mon, 02 Aug 2021 22:16:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627967782; cv=none; d=google.com; s=arc-20160816; b=VKKL+/fzoqNjG+W9JgPzKtsWD/+6H2vDq/bwokLhy52cu1dRI9KTyvtdnMGrniyRt8 j9ENVitBudroZxAeeB8OxdOm1go1+qTjZ+S0Apo9/2Kfc2Xu+V+vbY4PXzme3tFkZtoU BCjgJoImevviVfTgAdVfRZAv2kd1kveOtkvcUmB4w7+3TRDH4yJjp9239Dzd9D1KWpDc jR2YDMejAN1aK00UbP7O0wZ7EalJdoDRKCT1stHW7WfDrPwv04iQQAmojUfxtd4ci566 1eYavmCfPMrIsR4TA7VTj9YLlePhNr7dO+dfZCGdK3ESF4YP26+EdTjIwSj1fqNlsF0P Y4Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JLxgCxGwWj4l1oOSZ7lTOPxngZlLQfqdamjxMbXapkk=; b=RNCjjs7T/kJLRsZJypD2MGM6HR2E3FdiLKqjQu7VBYrC5iTu3twsuIBVd3fKbP7Fqa VxlUkqT7YRXYCPO4vD02xfgV724pI7PsWOhFxDpaTCQxS3btnRsJhWqJbGu1G7xo4lJv cPPE5PDG2I2ps/xapCzDS0WyvRlUnFlansDPE9471wiPadnO2bRoMO2FzuEvMzdCmCNB CowjuwPIMygiUUc5l4kvXJ8QdHsxcBjrW5dP2/em7ZIuX6sdj/Ay7uQ9xb2JgxDAVLN+ 1EjlwZoIdYZlzM07ad62EKJG4pqfA0KHGt6Qz0AZ5RsjriBhOI5FVOgJTejvA8189FzD CSig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S8P8vaGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si13920206jaf.48.2021.08.02.22.16.11; Mon, 02 Aug 2021 22:16:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S8P8vaGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234129AbhHCFOP (ORCPT + 99 others); Tue, 3 Aug 2021 01:14:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:60424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233737AbhHCFOJ (ORCPT ); Tue, 3 Aug 2021 01:14:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24BA160EE7; Tue, 3 Aug 2021 05:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627967638; bh=xa4VRMf9MHhvAN8b2TBx4R7NfCpyIy5U5JlFqM/1uNE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S8P8vaGLwYMlwvmup3upXwU24mcWEGu0OPG2JbwWw6crE1YM/9PHqg2+0oCTThMjD /Vp/V2SSevpk0kSCYZOaIHagSTH6YGEXyweYO4PSWbcqrrLkE14aXLMOrNVfw7vKQo k/lPh15+fJcfzvJRSQ0xGxW2SyAKUouVwqkdYvHs= Date: Tue, 3 Aug 2021 07:13:56 +0200 From: Greg Kroah-Hartman To: Pete Zaitcev Cc: Salah Triki , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: class: usblp: replace conditional statement with min() Message-ID: References: <20210803002806.GA1541734@pc> <20210802205022.357279fc@suzdal.zaitcev.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210802205022.357279fc@suzdal.zaitcev.lan> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 02, 2021 at 08:50:22PM -0500, Pete Zaitcev wrote: > On Tue, 3 Aug 2021 01:28:06 +0100 > Salah Triki wrote: > > > Replace conditional statement with min() in order to make code cleaner. Issue > > found by coccinelle. > > > +++ b/drivers/usb/class/usblp.c > > request, !!dir, recip, value, index, len, retval); > > - return retval < 0 ? retval : 0; > > + return min(retval, 0); > > } > > I'm very much against this change. The function min() is there > for numeric values. But here we have a situation where we > do one thing if there was an error, and another thing if > there was no error. > > This sort of abuse is exactly why blindly clicking heels > whenever a tool tells you is not optimal. > > If the objective is to shut the tool up, please consider > the following instead: > > diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c > index 9596e4279294..bbcbcf199fa9 100644 > --- a/drivers/usb/class/usblp.c > +++ b/drivers/usb/class/usblp.c > @@ -264,7 +264,9 @@ static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, i > dev_dbg(&usblp->intf->dev, > "usblp_control_msg: rq: 0x%02x dir: %d recip: %d value: %d idx: %d len: %#x result: %d\n", > request, !!dir, recip, value, index, len, retval); > - return retval < 0 ? retval : 0; > + if (retval < 0) > + return retval; > + return 0; > } I agree with Pete here, this is the "correct" fix for this, using min() is not ok here. thanks, greg k-h