mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Benoit Cousson <bcousson@baylibre.com>,
	Patrick Titiano <ptitiano@baylibre.com>,
	LM Sensors <lm-sensors@lm-sensors.org>
Subject: Re: [PATCH v2 3/3] hwmon: tmp401: bail-out from tmp401_probe() in case of write errors
Date: Thu, 4 Dec 2014 08:25:21 -0800	[thread overview]
Message-ID: <20141204162521.GD7385@roeck-us.net> (raw)
In-Reply-To: <1417706574-1023-4-git-send-email-bgolaszewski@baylibre.com>

On Thu, Dec 04, 2014 at 04:22:54PM +0100, Bartosz Golaszewski wrote:
> The return value of i2c_smbus_read_byte_data() is checked in
> tmp401_init_client(), but only a warning is printed and the device is
> registered anyway. This leads to devices being registered even if they
> cannot be physically detected.
> 
> Bail-out from probe in case of write errors and notify the user.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/hwmon/tmp401.c | 29 ++++++++++++++++++-----------
>  1 file changed, 18 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
> index a5f0973..ce7e579 100644
> --- a/drivers/hwmon/tmp401.c
> +++ b/drivers/hwmon/tmp401.c
> @@ -618,10 +618,10 @@ static const struct attribute_group tmp432_group = {
>   * Begin non sysfs callback code (aka Real code)
>   */
>  
> -static void tmp401_init_client(struct tmp401_data *data,
> -			       struct i2c_client *client)
> +static int tmp401_init_client(struct tmp401_data *data,
> +			      struct i2c_client *client)
>  {
> -	int config, config_orig;
> +	int config, config_orig, status;
>  
>  	/* Set the conversion rate to 2 Hz */
>  	i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
> @@ -629,16 +629,21 @@ static void tmp401_init_client(struct tmp401_data *data,
>  
>  	/* Start conversions (disable shutdown if necessary) */
>  	config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
> -	if (config < 0) {
> -		dev_warn(&client->dev, "Initialization failed!\n");
> -		return;
> -	}
> +	if (config < 0)
> +		return config;
>  
>  	config_orig = config;
>  	config &= ~TMP401_CONFIG_SHUTDOWN;
>  
> -	if (config != config_orig)
> -		i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config);
> +	if (config != config_orig) {
> +		status = i2c_smbus_write_byte_data(client,
> +						   TMP401_CONFIG_WRITE,
> +						   config);
> +		if (status < 0)
> +			return status;

Just pre-initialize status to 0 and return status unconditionally.

Thanks,
Guenter

      reply	other threads:[~2014-12-04 16:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04 15:22 [PATCH v2 0/3] hwmon: tmp401: support for TMP435 and fix for a probe issue Bartosz Golaszewski
2014-12-04 15:22 ` [PATCH v2 1/3] hwmon: tmp401: add support for TI TMP435 Bartosz Golaszewski
2014-12-04 16:23   ` Guenter Roeck
2014-12-04 15:22 ` [PATCH v2 2/3] hwmon: tmp401: add TMP435 to the list of supported chips in docs and Kconfig Bartosz Golaszewski
2014-12-04 15:22 ` [PATCH v2 3/3] hwmon: tmp401: bail-out from tmp401_probe() in case of write errors Bartosz Golaszewski
2014-12-04 16:25   ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141204162521.GD7385@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=bcousson@baylibre.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    --cc=ptitiano@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome