From nobody Sun Nov 24 20:27:22 2024 Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 516031AB51B; Sat, 2 Nov 2024 19:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577366; cv=none; b=InRmO/UId8bfQ8dUG+eGo55axoRlRi+ysGwoMT9B+K811DRKY8HMDNkbumK75LSYvYpxmFu63fp7kKZtIw8bHfbnynjuFRSzWj0u22VRrE1Gd6wV0SUnIjXrIoomzWfUxV54H/CwX/4tuzNr2+DeO8JiJKOfSMCtLtFUa1INM84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577366; c=relaxed/simple; bh=28wySHybmNzvDTM0gtkqKltIIyZ02cQb/jqmatJ5bvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kH63BdhrpqD5QtPI20YcFe2fGqhnIB/wbLzZTMqrY/yk5k8NRU4fqLbYz6ge94Lh3hUK5awm5P0gM0K0LNty25OEnEdhiE76g+gby8I+rVn37WajL6kKj3ul7eB8QcL1Lqmkpqj2sDC7CGyyDj8Ux4JVEMHomrv2me4fDotCaV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=ZBbr8wfw; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="ZBbr8wfw" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 605304C847; Sat, 2 Nov 2024 19:56:03 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 4/6] iio: light: stk3310: use dev_err_probe where possible Date: Sat, 2 Nov 2024 15:50:41 -0400 Message-ID: <20241102195037.3013934-11-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1730577364; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=EOQ+icUlK1H5YL/QrrfHa7ZgZuPTLdaho4son5PhToI=; b=ZBbr8wfwo3qQ6VZx2PM+mCKxgFgJ/XzgEIbWYqxxV53kdJtu1IBxYs/14HzjzlLCmsI4jP h0+CYKNKBlldsH12AbP+Fb/Fi3RtW5SWO0+akM3HX4gLAKYE1ihUITbcPR4JxGcegEhi5O WVHfe7SmFGbvI01CTC/SvMfZUL4D0qI= Content-Type: text/plain; charset="utf-8" Using dev_err_probe instead of dev_err and return makes the errors easier to understand by including the error name, and saves a little code. Signed-off-by: Aren Moynihan --- Notes: Changes in v4: - Get a struct device ahead of time so it can be passed as "dev" instead of "&client->dev" =20 No changes in v3 =20 Added in v2 drivers/iio/light/stk3310.c | 61 ++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index f93689c61f44..c9a3f02bdd80 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -61,12 +61,12 @@ #define STK3310_REGFIELD(name) \ do { \ data->reg_##name =3D \ - devm_regmap_field_alloc(&client->dev, regmap, \ + devm_regmap_field_alloc(dev, regmap, \ stk3310_reg_field_##name); \ - if (IS_ERR(data->reg_##name)) { \ - dev_err(&client->dev, "reg field alloc failed.\n"); \ - return PTR_ERR(data->reg_##name); \ - } \ + if (IS_ERR(data->reg_##name)) \ + return dev_err_probe(dev, \ + PTR_ERR(data->reg_##name), \ + "reg field alloc failed.\n"); \ } while (0) =20 static const struct reg_field stk3310_reg_field_state =3D @@ -517,10 +517,8 @@ static int stk3310_init(struct iio_dev *indio_dev) =20 state =3D STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS; ret =3D stk3310_set_state(data, state); - if (ret < 0) { - dev_err(&client->dev, "failed to enable sensor"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "failed to enable sensor\n"); =20 ret =3D devm_add_action_or_reset(&client->dev, stk3310_set_state_disable,= data); if (ret) @@ -529,9 +527,9 @@ static int stk3310_init(struct iio_dev *indio_dev) /* Enable PS interrupts */ ret =3D regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN); if (ret < 0) - dev_err(&client->dev, "failed to enable interrupts!\n"); + return dev_err_probe(dev, ret, "failed to enable interrupts!\n"); =20 - return ret; + return 0; } =20 static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg) @@ -560,14 +558,14 @@ static const struct regmap_config stk3310_regmap_conf= ig =3D { static int stk3310_regmap_init(struct stk3310_data *data) { struct regmap *regmap; - struct i2c_client *client; + struct i2c_client *client =3D data->client; + struct device *dev =3D &client->dev; =20 - client =3D data->client; regmap =3D devm_regmap_init_i2c(client, &stk3310_regmap_config); - if (IS_ERR(regmap)) { - dev_err(&client->dev, "regmap initialization failed.\n"); - return PTR_ERR(regmap); - } + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "regmap initialization failed.\n"); + data->regmap =3D regmap; =20 STK3310_REGFIELD(state); @@ -654,12 +652,11 @@ static int stk3310_probe(struct i2c_client *client) int ret; struct iio_dev *indio_dev; struct stk3310_data *data; + struct device *dev =3D &client->dev; =20 indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); - if (!indio_dev) { - dev_err(&client->dev, "iio allocation failed!\n"); - return -ENOMEM; - } + if (!indio_dev) + return dev_err_probe(dev, -ENOMEM, "iio allocation failed!\n"); =20 data =3D iio_priv(indio_dev); data->client =3D client; @@ -675,7 +672,7 @@ static int stk3310_probe(struct i2c_client *client) ret =3D devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(data->supplies), data->supplies); if (ret) - return dev_err_probe(&client->dev, ret, "get regulators failed\n"); + return dev_err_probe(dev, ret, "get regulators failed\n"); =20 ret =3D stk3310_regmap_init(data); if (ret < 0) @@ -689,13 +686,11 @@ static int stk3310_probe(struct i2c_client *client) =20 ret =3D stk3310_regulators_enable(data); if (ret) - return dev_err_probe(&client->dev, ret, - "regulator enable failed\n"); + return dev_err_probe(dev, ret, "regulator enable failed\n"); =20 ret =3D devm_add_action_or_reset(&client->dev, stk3310_regulators_disable= , data); if (ret) - return dev_err_probe(&client->dev, ret, - "failed to register regulator cleanup\n"); + return dev_err_probe(dev, ret, "failed to register regulator cleanup\n"); =20 ret =3D stk3310_init(indio_dev); if (ret < 0) @@ -708,18 +703,14 @@ static int stk3310_probe(struct i2c_client *client) IRQF_TRIGGER_FALLING | IRQF_ONESHOT, STK3310_EVENT, indio_dev); - if (ret < 0) { - dev_err(&client->dev, "request irq %d failed\n", - client->irq); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "request irq %d failed\n", + client->irq); } =20 ret =3D devm_iio_device_register(&client->dev, indio_dev); - if (ret < 0) { - dev_err(&client->dev, "device_register failed\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "device_register failed\n"); =20 return 0; } --=20 2.47.0