Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp918985pxf; Wed, 7 Apr 2021 15:04:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBvUg1S2MsT0aOw1Sh4c/4ldKOmWucpquQR4iadDP1BU9M2zL9YhTBBxV2N0rCbORgGdj7 X-Received: by 2002:a17:90a:d350:: with SMTP id i16mr5365331pjx.226.1617833045907; Wed, 07 Apr 2021 15:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617833045; cv=none; d=google.com; s=arc-20160816; b=E8xdDUU/rhpqvBA1QMd0YEkVkfc5ghdO6QLE6KQnCyz+e95Y8/5Sj948Zmam+e9GXY eNXYFh9dPcJJwwCRwNat4ZCijCbh6QmYzCo/ayYM9Yp3pM9Jc9bzULG1p2gM8fNx1kgS kvsNONGRO7KlTwQFUSrMetOKbOFjLT0eccy0aLloUxP65sSYdYvfik9/TzXR15nYcRez w9QdQH56GLJMlK5Ia8h7z8RjednQPAWVWgN8wKSXjzIpmDKgWH1COpStsnDLGHdTdUeY J/C/4rw4RamB7m8XURG2TTDZiyHv/fG/+WWmtQxixwEJvstOYZWMGXSMlZC/bwVmBsyi MMSQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ABMI0EjtBbX5kyaLQx8W5hqb07nbu/QgaIGt0Obbm7A=; b=XafnciV3VychLbSsIY5KvlZ/BHMx7+DRKSEntujKGjyNxP3y2yS68vBTSJ3gdRmUnU WLX+d/1guuzeHXjZzJUuUSjbBJ1lhWrpNtuuN4uZQKOAZKgiFVchfxzHtokYgKGFBnt5 Dm81Ay41+vJnBEG/11AhHCQa26wwZN9lLQ6UmujpZdpcvmzwEJk3BcEILFHz7Zbj4pm8 W/3nWLgHGnaMI2q+730q+2XLZgtWlQdBBooSFKpW6q54RI6iEWGGe+WD4DhYvkCFuLmC l+ll0Q7cvQEJl9CQfc8sWbPMZvesB8NXNVvdaXs/uWYbTwM0cD26pNO3WG3y+nZNyqE8 PbOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=xkrCS7QR; 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=REJECT sp=NONE dis=NONE) header.from=pqgruber.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si26194372plv.281.2021.04.07.15.03.53; Wed, 07 Apr 2021 15:04:05 -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=@pqgruber.com header.s=mail header.b=xkrCS7QR; 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=REJECT sp=NONE dis=NONE) header.from=pqgruber.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbhDGUr6 (ORCPT + 99 others); Wed, 7 Apr 2021 16:47:58 -0400 Received: from mail.pqgruber.com ([52.59.78.55]:39958 "EHLO mail.pqgruber.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhDGUr5 (ORCPT ); Wed, 7 Apr 2021 16:47:57 -0400 Received: from workstation.tuxnet (213-47-165-233.cable.dynamic.surfer.at [213.47.165.233]) by mail.pqgruber.com (Postfix) with ESMTPSA id 98964C6B24A; Wed, 7 Apr 2021 22:47:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1617828466; bh=ABMI0EjtBbX5kyaLQx8W5hqb07nbu/QgaIGt0Obbm7A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xkrCS7QRsSaS0nLAC91OgjhcPtmPAg7uODIsItOQ19L0/F5Ay0W8JHw58ubc8e77d sCB0uXAniAww2PIfOz8+zZsnaPShGuzIcoF6NwzLbTPMYaPdLUv2+tttq7onOJtj20 c2tPI+/mMkabAQfCCzyok5TFSUcRT6xy9rzO7Imw= Date: Wed, 7 Apr 2021 22:47:45 +0200 From: Clemens Gruber To: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Cc: linux-pwm@vger.kernel.org, Thierry Reding , Sven Van Asbroeck , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 8/8] pwm: pca9685: Add error messages for failed regmap calls Message-ID: References: <20210406164140.81423-1-clemens.gruber@pqgruber.com> <20210406164140.81423-8-clemens.gruber@pqgruber.com> <20210407061619.fl6ffos6csvgtnjh@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210407061619.fl6ffos6csvgtnjh@pengutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 07, 2021 at 08:16:19AM +0200, Uwe Kleine-K?nig wrote: > On Tue, Apr 06, 2021 at 06:41:40PM +0200, Clemens Gruber wrote: > > Regmap operations can fail if the underlying subsystem is not working > > properly (e.g. hogged I2C bus, etc.) > > As this is useful information for the user, print an error message if it > > happens. > > Let probe fail if the first regmap_read or the first regmap_write fails. > > > > Signed-off-by: Clemens Gruber > > --- > > Changes since v6: > > - Rebased > > > > drivers/pwm/pwm-pca9685.c | 83 ++++++++++++++++++++++++++++----------- > > 1 file changed, 59 insertions(+), 24 deletions(-) > > > > diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c > > index cf0c98e4ef44..8a4993882b40 100644 > > --- a/drivers/pwm/pwm-pca9685.c > > +++ b/drivers/pwm/pwm-pca9685.c > > @@ -107,6 +107,30 @@ static bool pca9685_prescaler_can_change(struct pca9685 *pca, int channel) > > return test_bit(channel, pca->pwms_enabled); > > } > > > > +static int pca9685_read_reg(struct pca9685 *pca, unsigned int reg, unsigned int *val) > > +{ > > + struct device *dev = pca->chip.dev; > > + int err; > > + > > + err = regmap_read(pca->regmap, reg, val); > > + if (err != 0) > > + dev_err(dev, "regmap_read of register 0x%x failed: %d\n", reg, err); > > Please use %pe to emit the error code instead of %d. Will do. > > > + > > + return err; > > +} > > + > > +static int pca9685_write_reg(struct pca9685 *pca, unsigned int reg, unsigned int val) > > +{ > > + struct device *dev = pca->chip.dev; > > + int err; > > + > > + err = regmap_write(pca->regmap, reg, val); > > + if (err != 0) > > + dev_err(dev, "regmap_write to register 0x%x failed: %d\n", reg, err); > > + > > + return err; > > +} > > + > > /* Helper function to set the duty cycle ratio to duty/4096 (e.g. duty=2048 -> 50%) */ > > static void pca9685_pwm_set_duty(struct pca9685 *pca, int channel, unsigned int duty) > > { > > @@ -115,12 +139,12 @@ static void pca9685_pwm_set_duty(struct pca9685 *pca, int channel, unsigned int > > > > if (duty == 0) { > > /* Set the full OFF bit, which has the highest precedence */ > > - regmap_write(pca->regmap, REG_OFF_H(channel), LED_FULL); > > + pca9685_write_reg(pca, REG_OFF_H(channel), LED_FULL); > > You didn't check all return codes? How did you select the calls to > check? No, because it would become a big mess and really obstruct readability in my opinion. So I chose some kind of middleground: I decided to check the first regmap_read and regmap_write in probe and return the error code if something goes wrong there. If something goes wrong after probe, I only print an error message. Is that acceptable? Thanks, Clemens