Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1417602yba; Sun, 5 May 2019 06:02:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCdIbDXYerX//lJIyJ4bCS3bV3x4W5ULro6haPGl8WiRegU/RT/aREt1M2ot2PqEHRlik7 X-Received: by 2002:a17:902:f24:: with SMTP id 33mr24664818ply.33.1557061375484; Sun, 05 May 2019 06:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557061375; cv=none; d=google.com; s=arc-20160816; b=TG4Ml8pGU885KW2mc8nHKckavMfwJ6JYJ1cUiVAQVr7CU86k8xSgMNGFQogrASU97o DeCem7Ul8EAnCZGVJP1e3wE/65SWn60wayrte3BHgSfsWT7x1VvwQozb4CB7mc2E87Sg ckb1VgE5mh/7rOiYbMX2LI+FLaNSRJ1IHTbcfjqDBVGpoComC9yc5CJRc49GgilyZsdF Xy28O2cc/mKHGVivsgp4ovFc9wiwY5dZ6CYkkbFF5AV/FtQR4eKmc4eCZ8q0u9YdvoU4 POQ8KqGibmpFTJqAVqLAZnY61N8BrUyACaA8y4Jz3uxO8EvSVpLhdZo0g4ksoYaezX05 jKeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=O8RrqJ4MLPnupdRRQmqYkZN9F94pV13sQa0tzxatC70=; b=ZrzbcqWQvvTrG5er3RPa/jszLPM8QT85FBv3BTidTddrRBtt2rc9u8tDMNfgFVgsLN ypP7FIaUbeTTKniFWk4FCqWT4wqmMt3VKM0TO29bvljphPVRKwytfdqywhJk4GSkyGgP Va6DIhoUG3W352ea+QXXVIdCZaPrRYH3NvwWysizsn1UZU7gk9TlNeIjHwziKCkWTEw3 2bz1YOsSGmyTgjpu4GUDyO37M1IRA7QyiYR81U/qTwe5NgvU/BdyXPUfRjcrWEHYg1TV VT2PVSOBKTrQjPxwutSpjKT7OKIQyMb6Dgvq/SLWJbSvXjjo6/QGBjHc8U3O7OA60C+u 5fLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UCMCuu9W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si9665407pgc.62.2019.05.05.06.02.37; Sun, 05 May 2019 06:02:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UCMCuu9W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727534AbfEEM7p (ORCPT + 99 others); Sun, 5 May 2019 08:59:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:46626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbfEEM7o (ORCPT ); Sun, 5 May 2019 08:59:44 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 ADB492082F; Sun, 5 May 2019 12:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557061183; bh=OYgI343ZtwZsMYkCCr5+/f4njEWi3WQsFQBAc5e2gCw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UCMCuu9WXNG8dYbFQCyhkCsmJgm1anx2J8O+kQuQVvmYyXF8GvIzq7HZakKjmeALn Rup1nw2pHiwYbdBjvLKeDX3foK6bAlOBDR1p8ahuZdubCtUiPb+lx0OhqBIb/vg2nP lOz2nuuLA338iDCf5Dsxe2DW17f/Zb/uinGwlI0k= Date: Sun, 5 May 2019 13:59:37 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: Melissa Wen , Lars-Peter Clausen , Michael Hennerich , Stefan Popa , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , Barry Song <21cnbao@gmail.com>, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, LKML , kernel-usp@googlegroups.com Subject: Re: [PATCH 3/4] staging: iio: ad7150: simplify i2c SMBus return treatment Message-ID: <20190505135937.03e7be65@archlinux> In-Reply-To: References: <18725f7ddc3ac42b1c781b1848b05fabd4bd8320.1556919363.git.melissa.srw@gmail.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 4 May 2019 13:36:43 +0300 Alexandru Ardelean wrote: > On Sat, May 4, 2019 at 1:26 AM Melissa Wen wrote: > > > > Since i2c_smbus_write_byte_data returns no-positive value, this commit > > making the treatment of its return value less verbose. > > > > Signed-off-by: Melissa Wen > > --- > > drivers/staging/iio/cdc/ad7150.c | 10 +++------- > > 1 file changed, 3 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c > > index 4ba46fb6ac02..3a4572a9e5ec 100644 > > --- a/drivers/staging/iio/cdc/ad7150.c > > +++ b/drivers/staging/iio/cdc/ad7150.c > > @@ -201,16 +201,12 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, > > ret = i2c_smbus_write_byte_data(chip->client, > > ad7150_addresses[chan][4], > > sens); > > - if (ret < 0) > > + if (ret) > > For i2c_smbus_write_byte_data(), checking "ret < 0" or non-zero, is the same. > Changing this doesn't have any added value. The slight note I'd add to that is that if you are (and I think you should) just doing return i2c_smbus_write_byte_data() for the last call then that effectively means we are assuming ret is never positive in some paths and not others. I'd encourage consistency so would would prefer this is changed to if (ret). As in the earlier patch the line between what is noise in a staging (or new driver) and what is noise in a driver that has been outside staging for years is different. Not so good for Alex perhaps if there is a chance Analog will backport fixes for their drivers, but tough luck :) > > > return ret; > > - > > - ret = i2c_smbus_write_byte_data(chip->client, > > + else > > + return i2c_smbus_write_byte_data(chip->client, > > ad7150_addresses[chan][5], > > timeout); > > The introduction of the "else" branch is a bit noisy. > The code was a bit neater (and readable) before the else branch, and > functionally identical. > > Well, when I say neater before, you have to understand, that I (and I > assume that some other people who write drivers) have a slight > fixation for this pattern: > > example1: > ret = fn1(); > > if (ret < 0) // could also be just "if (ret)" > return ret; > > ret = fn2(); > if (ret < 0) // could also be just "if (ret)" > return ret; > > example1a: > +ret = fn3(); > +if (ret < 0) // could also be just "if (ret)" > + return ret; > > > Various higher-level programming languages, will discourage this > pattern in favor of neater patterns. > > I personally, have a few arguments in favor of this pattern: > 1) it is closer to how the machine code ; so, closer to how a > low-level instruction looks like > 2) if (ever) this needs to be patched, the patch could be neat (see > example1a) ; the examle assumes that it's been added via a patch at a > later point in time > 3) it keeps indentation level to a minimum ; this also aligns with > kernel-coding guidelines > (https://www.kernel.org/doc/html/v4.10/process/coding-style.html ) > (indentation seems a bit OCD-like when someone points it out at a > review, but it has it's value over time) Nicely laid out argument. Strongest one is the maintainability and reviewability aspect of it being how kernel code is done and hence takes every so slightly less thought ;) Errors paths are indented, good paths not (in general). Jonathan > > > - if (ret < 0) > > - return ret; > > - > > - return 0; > > } > > > > static int ad7150_write_event_config(struct iio_dev *indio_dev, > > -- > > 2.20.1 > >