From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E48B7D527 for ; Mon, 7 Nov 2022 15:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1667834105; bh=jv4L3CMeB4iLALBmYv14TMVcf39jXzd1TidE3Takkv4=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=Ia4gLgAFQpTDBH6+JLLSOZxZNBdVFuEzqSypZeFYPEzFM6O1lmzAi0JE6e/srpXTj /2xc+xGctFYUCfblUIsTIELcxwpMQ0wJVoqHAK1tuxpedPCOst+ZeS85jlBdNlVeRI bNR974G2RUjeQtOKYTVxp1MaRaD2+Vma40LcqL2Y= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Mon, 7 Nov 2022 16:15:05 +0100 (CET) X-EA-Auth: MrUVv6JFM3UQRU8f0izViYsX4i9dq+0Kl5xYHlgXIlPtB/51k3XCAWeWfHnd4CB3gHATy+AJR4jDoNRz5Ft0sRJvECjcN/TQ Date: Mon, 7 Nov 2022 20:45:00 +0530 From: Deepak R Varma To: Dan Carpenter Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Greg Kroah-Hartman , linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: iio: meter: use min() for comparison and assignment Message-ID: References: Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Nov 07, 2022 at 04:08:31PM +0300, Dan Carpenter wrote: > On Mon, Nov 07, 2022 at 09:40:00AM +0530, Deepak R Varma wrote: > > Simplify code by using recommended min helper macro for logical > > evaluation and value assignment. This issue is identified by > > coccicheck using the minmax.cocci file. > > > > Signed-off-by: Deepak R Varma > > --- > > drivers/staging/iio/meter/ade7854-i2c.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c > > index a9a06e8dda51..a6ce7b24cc8f 100644 > > --- a/drivers/staging/iio/meter/ade7854-i2c.c > > +++ b/drivers/staging/iio/meter/ade7854-i2c.c > > @@ -61,7 +61,7 @@ static int ade7854_i2c_write_reg(struct device *dev, > > unlock: > > mutex_unlock(&st->buf_lock); > > > > - return ret < 0 ? ret : 0; > > + return min(ret, 0); > > The original code is better. > > If it's a failure return the error code. If it's not return zero. > > You can only compare apples to apples. min() makes sense if you're > talking about two lengths. But here if ret is negative that's an error > code. If it's positive that's the number of bytes. If the error > code is less than the number of bytes then return that? What??? It > makes no sense. Thanks for your view point. I agree. > > In terms of run time, this patch is fine but in terms of reading the > code using min() makes it less readable. Okay, The proposal does not make much difference, so will leave the original line as is. Thank you, ./drv > > regards, > dan carpenter >