From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B31CEC433DB for ; Tue, 29 Dec 2020 14:29:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7710920825 for ; Tue, 29 Dec 2020 14:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726181AbgL2O3l (ORCPT ); Tue, 29 Dec 2020 09:29:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:56612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgL2O3k (ORCPT ); Tue, 29 Dec 2020 09:29:40 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7746A20825; Tue, 29 Dec 2020 14:28:59 +0000 (UTC) Date: Tue, 29 Dec 2020 14:28:56 +0000 From: Jonathan Cameron To: Chunyan Zhang Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Orson Zhai , Baolin Wang , linux-iio@vger.kernel.org Subject: Re: [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it Message-ID: <20201229142856.3e5fbf10@archlinux> In-Reply-To: References: <20201222191618.3433-1-lars@metafoo.de> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Wed, 23 Dec 2020 13:39:24 +0800 Chunyan Zhang wrote: > On Wed, 23 Dec 2020 at 03:16, Lars-Peter Clausen wrote: > > > > Use DIV_ROUND_CLOSEST() instead of open-coding it. This makes it more clear > > what is going on for the casual reviewer. > > > > Generated using the following the Coccinelle semantic patch. > > > > // > > @@ > > expression x, y; > > @@ > > -((x) + ((y) / 2)) / (y) > > +DIV_ROUND_CLOSEST(x, y) > > // > > > > Signed-off-by: Lars-Peter Clausen > > Acked-by: Chunyan Zhang Applied to the togreg branch of iio.git and pushed out as testing. Thanks, Jonathan > > Thanks, > Chunyan > > > --- > > drivers/iio/adc/sc27xx_adc.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c > > index aa32a1f385e2..301cf66de695 100644 > > --- a/drivers/iio/adc/sc27xx_adc.c > > +++ b/drivers/iio/adc/sc27xx_adc.c > > @@ -307,7 +307,7 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel, > > > > sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator); > > > > - return (volt * denominator + numerator / 2) / numerator; > > + return DIV_ROUND_CLOSEST(volt * denominator, numerator); > > } > > > > static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data, > > -- > > 2.20.1 > >