From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752579AbbHRJRW (ORCPT ); Tue, 18 Aug 2015 05:17:22 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:29350 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751296AbbHRJRU (ORCPT ); Tue, 18 Aug 2015 05:17:20 -0400 Date: Tue, 18 Aug 2015 12:16:33 +0300 From: Dan Carpenter To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Dan Murphy , Krzysztof Kozlowski , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch v3] iio: tsl4531: fix error handling in tsl4531_check_id() Message-ID: <20150818091633.GC3965@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55D1F82F.8020303@ti.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tsl4531_check_id() function returned 1 on "found" and 0 on "not found" and negative error codes on failure. This was non-standard and bug prone. The caller treated all non-zero values including error codes as "found". This patch fixes it by changing the tsl4531_check_id() to return zero on success or a negative error code, and updates the caller. Signed-off-by: Dan Carpenter --- v3: slightly different fix again v2: different fix diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c index 2697918..cf94ec7 100644 --- a/drivers/iio/light/tsl4531.c +++ b/drivers/iio/light/tsl4531.c @@ -158,9 +158,9 @@ static int tsl4531_check_id(struct i2c_client *client) case TSL45313_ID: case TSL45315_ID: case TSL45317_ID: - return 1; - default: return 0; + default: + return -ENODEV; } } @@ -180,9 +180,10 @@ static int tsl4531_probe(struct i2c_client *client, data->client = client; mutex_init(&data->lock); - if (!tsl4531_check_id(client)) { + ret = tsl4531_check_id(client); + if (ret) { dev_err(&client->dev, "no TSL4531 sensor\n"); - return -ENODEV; + return ret; } ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL,