From: Guenter Roeck <linux@roeck-us.net>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-hwmon@vger.kernel.org, Jean Delvare <jdelvare@suse.com>
Subject: Re: [PATCH] hwmon: Reduce indentation level in __hwmon_device_register()
Date: Mon, 4 May 2020 18:54:39 -0700 [thread overview]
Message-ID: <20200505015439.GA139472@roeck-us.net> (raw)
On Mon, May 04, 2020 at 11:57:44PM +0900, Akinobu Mita wrote:
> Reduce indentation level in __hwmon_device_register() by preparing a
> helper function.
>
> This just improves code readability. No functional change.
>
Applied.
Guenter
> Cc: Jean Delvare <jdelvare@suse.com>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
> drivers/hwmon/hwmon.c | 68 ++++++++++++++++++++++++++-----------------
> 1 file changed, 42 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 6a30fb453f7a..dcd4445d4570 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -179,8 +179,40 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index)
>
> return 0;
> }
> +
> +static int hwmon_thermal_register_sensors(struct device *dev)
> +{
> + struct hwmon_device *hwdev = to_hwmon_device(dev);
> + const struct hwmon_chip_info *chip = hwdev->chip;
> + const struct hwmon_channel_info **info = chip->info;
> + void *drvdata = dev_get_drvdata(dev);
> + int i;
> +
> + for (i = 1; info[i]; i++) {
> + int j;
> +
> + if (info[i]->type != hwmon_temp)
> + continue;
> +
> + for (j = 0; info[i]->config[j]; j++) {
> + int err;
> +
> + if (!(info[i]->config[j] & HWMON_T_INPUT) ||
> + !chip->ops->is_visible(drvdata, hwmon_temp,
> + hwmon_temp_input, j))
> + continue;
> +
> + err = hwmon_thermal_add_sensor(dev, j);
> + if (err)
> + return err;
> + }
> + }
> +
> + return 0;
> +}
> +
> #else
> -static int hwmon_thermal_add_sensor(struct device *dev, int index)
> +static int hwmon_thermal_register_sensors(struct device *dev)
> {
> return 0;
> }
> @@ -596,7 +628,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> {
> struct hwmon_device *hwdev;
> struct device *hdev;
> - int i, j, err, id;
> + int i, err, id;
>
> /* Complain about invalid characters in hwmon name attribute */
> if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
> @@ -664,30 +696,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> if (dev && dev->of_node && chip && chip->ops->read &&
> chip->info[0]->type == hwmon_chip &&
> (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
> - const struct hwmon_channel_info **info = chip->info;
> -
> - for (i = 1; info[i]; i++) {
> - if (info[i]->type != hwmon_temp)
> - continue;
> -
> - for (j = 0; info[i]->config[j]; j++) {
> - if (!chip->ops->is_visible(drvdata, hwmon_temp,
> - hwmon_temp_input, j))
> - continue;
> - if (info[i]->config[j] & HWMON_T_INPUT) {
> - err = hwmon_thermal_add_sensor(hdev, j);
> - if (err) {
> - device_unregister(hdev);
> - /*
> - * Don't worry about hwdev;
> - * hwmon_dev_release(), called
> - * from device_unregister(),
> - * will free it.
> - */
> - goto ida_remove;
> - }
> - }
> - }
> + err = hwmon_thermal_register_sensors(hdev);
> + if (err) {
> + device_unregister(hdev);
> + /*
> + * Don't worry about hwdev; hwmon_dev_release(), called
> + * from device_unregister(), will free it.
> + */
> + goto ida_remove;
> }
> }
>
> --
> 2.20.1
>
next reply other threads:[~2020-05-05 1:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 1:54 Guenter Roeck [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-05-04 14:57 [PATCH] hwmon: Reduce indentation level in __hwmon_device_register() Akinobu Mita
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=20200505015439.GA139472@roeck-us.net \
--to=linux@roeck-us.net \
--cc=akinobu.mita@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).