From: Luka Kovacic <luka.kovacic@sartura.hr>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
linux-hwmon@vger.kernel.org,
"Linux LED Subsystem" <linux-leds@vger.kernel.org>,
devicetree <devicetree@vger.kernel.org>,
"Lee Jones" <lee.jones@linaro.org>, "Pavel Machek" <pavel@ucw.cz>,
"Dan Murphy" <dmurphy@ti.com>, "Rob Herring" <robh+dt@kernel.org>,
"Jean Delvare" <jdelvare@suse.com>,
"Guenter Roeck" <linux@roeck-us.net>,
"Marek Behún" <marek.behun@nic.cz>,
"Luka Perkov" <luka.perkov@sartura.hr>,
"Robert Marko" <robert.marko@sartura.hr>
Subject: Re: [PATCH v6 3/6] drivers: hwmon: Add the iEi WT61P803 PUZZLE HWMON driver
Date: Fri, 23 Oct 2020 23:47:29 +0200 [thread overview]
Message-ID: <CADZsf3ZmeUZppsJaR7bT8y16L3Mj12tUfzo=hkV4nFgjN64Jqw@mail.gmail.com> (raw)
In-Reply-To: <CAHp75VdnOJKwvZUOsj3bbT8tK9uZN=NufDrdhUvS886bNUpWhA@mail.gmail.com>
Hi Andy,
On Tue, Oct 20, 2020 at 10:59 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Tue, Oct 20, 2020 at 1:19 AM Luka Kovacic <luka.kovacic@sartura.hr> wrote:
> >
> > Add the iEi WT61P803 PUZZLE HWMON driver, that handles the fan speed
> > control via PWM, reading fan speed and reading on-board temperature
> > sensors.
> >
> > The driver registers a HWMON device and a simple thermal cooling device to
> > enable in-kernel fan management.
> >
> > This driver depends on the iEi WT61P803 PUZZLE MFD driver.
>
> ...
>
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/* iEi WT61P803 PUZZLE MCU HWMON Driver
>
> Shouldn't be
> /*
> * IEI ...
>
> ?
>
> ...
>
> > +/**
> > + * struct iei_wt61p803_puzzle_thermal_cooling_device - Thermal cooling device instance
>
> > + *
>
> Please, remove all these blank lines in kernel doc descriptions.
>
> > + * @mcu_hwmon: MCU HWMON struct pointer
> > + * @tcdev: Thermal cooling device pointer
> > + * @name: Thermal cooling device name
> > + * @pwm_channel: PWM channel (0 or 1)
> > + * @cooling_levels: Thermal cooling device cooling levels
> > + */
>
> ...
>
> > +struct iei_wt61p803_puzzle_hwmon {
> > + struct iei_wt61p803_puzzle *mcu;
> > + unsigned char *response_buffer;
> > + bool thermal_cooling_dev_present[IEI_WT61P803_PUZZLE_HWMON_MAX_PWM_NUM];
> > + struct iei_wt61p803_puzzle_thermal_cooling_device
> > + *cdev[IEI_WT61P803_PUZZLE_HWMON_MAX_PWM_NUM];
>
> Isn't this constant a bit too long? Perhaps drop NUM (MAX would
> suffice I think) for a starter.
Okay, I'll drop NUM.
>
> > +};
>
> ...
>
> > + static unsigned char temp_sensor_ntc_cmd[4] = {
> > + IEI_WT61P803_PUZZLE_CMD_HEADER_START,
> > + IEI_WT61P803_PUZZLE_CMD_TEMP,
> > + IEI_WT61P803_PUZZLE_CMD_TEMP_ALL
>
> + comma.
>
> > + };
>
> Why not to be consistent with the rest assignments, choose either
> above form, or like you have done in the below functions.
Assignments, where the array content will not be modified with custom
values are done as above.
Although I could change these to the other form, if that makes it clearer.
> Also, why 4?
1 additional character is always required, as this array is passed by reference
to the iei_wt61p803_puzzle_write_command() function, which requires it to
store a calculated checksum of the array content.
This is done to avoid unnecessary copying of the array inside the MFD driver.
The checksum is a part of the command, so the driver and the MCU can check
the integrity of the sent data.
>
> > + size_t reply_size = 0;
>
> How is it used in all these functions?
I will add an additional check for the size of the received reply, as
it should be fixed.
>
> > + int ret;
> > +
> > + ret = iei_wt61p803_puzzle_write_command(mcu_hwmon->mcu, temp_sensor_ntc_cmd,
> > + sizeof(temp_sensor_ntc_cmd), resp_buf,
> > + &reply_size);
> > +
> > + if (ret)
> > + return ret;
> > +
> > + /* Check the number of NTC values (should be 0x32/'2') */
>
> > + if (resp_buf[3] != 0x32)
>
> Instead of comment in the parentheses, just do it here
> " != '2')"
>
> > + return -EIO;
>
> ...
>
> > +static int iei_wt61p803_puzzle_read(struct device *dev, enum hwmon_sensor_types type,
> > + u32 attr, int channel, long *val)
> > +{
> > + struct iei_wt61p803_puzzle_hwmon *mcu_hwmon = dev_get_drvdata(dev->parent);
> > + int ret;
> > +
> > + switch (type) {
> > + case hwmon_pwm:
>
> > + ret = iei_wt61p803_puzzle_read_pwm_channel(mcu_hwmon, channel, val);
> > + return ret;
>
> return iei_...(...);
> in all such cases.
>
> > + case hwmon_fan:
> > + ret = iei_wt61p803_puzzle_read_fan_speed(mcu_hwmon, channel, val);
> > + return ret;
> > + case hwmon_temp:
> > + ret = iei_wt61p803_puzzle_read_temp_sensor(mcu_hwmon, channel, val);
> > + return ret;
> > + default:
> > + return -EINVAL;
> > + }
> > +}
>
> ...
>
> > +static umode_t iei_wt61p803_puzzle_is_visible(const void *data, enum hwmon_sensor_types type,
> > + u32 attr, int channel)
> > +{
> > + switch (type) {
> > + case hwmon_pwm:
>
> > + switch (attr) {
> > + case hwmon_pwm_input:
> > + return 0644;
> > + default:
> > + return 0;
> > + }
>
> Isn't too long for
> if (attr == ...)
> return 0644;
> break;
>
> ...see below...
>
> > + case hwmon_fan:
> > + switch (attr) {
> > + case hwmon_fan_input:
> > + return 0444;
> > + default:
> > + return 0;
> > + }
> > + case hwmon_temp:
> > + switch (attr) {
> > + case hwmon_temp_input:
> > + return 0444;
> > + default:
> > + return 0;
> > + }
>
> > + default:
> > + return 0;
>
> break;
>
> > + }
>
> return 0;
>
> ?
>
> > +}
>
> ...
>
> > + mcu_hwmon->thermal_cooling_dev_present[pwm_channel] = true;
> > +
>
> > + num_levels = fwnode_property_read_u8_array(child, "cooling-levels", NULL, 0);
>
> fwnode_property_count_u8()
>
> > + if (num_levels > 0) {
>
> You can improve readability by reducing indentation level via
> replacement to negative conditional.
>
> > + cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL);
> > + if (!cdev)
> > + return -ENOMEM;
> > +
> > + cdev->cooling_levels = devm_kzalloc(dev, num_levels, GFP_KERNEL);
>
> For the sake of cleaness, shouldn't it be devm_kmalloc_array() ?
> (Note, zeroing is not needed if you read entire array)
I agree, this can be converted to devm_kmalloc_array().
>
> > + if (!cdev->cooling_levels)
> > + return -ENOMEM;
> > +
> > + ret = fwnode_property_read_u8_array(child, "cooling-levels",
> > + cdev->cooling_levels,
> > + num_levels);
> > + if (ret) {
> > + dev_err(dev, "Couldn't read property 'cooling-levels'");
> > + return ret;
> > + }
> > +
> > + snprintf(cdev->name, THERMAL_NAME_LENGTH, "iei_wt61p803_puzzle_%d", pwm_channel);
> > +
> > + cdev->tcdev = devm_thermal_of_cooling_device_register(dev, NULL,
> > + cdev->name, cdev, &iei_wt61p803_puzzle_cooling_ops);
> > + if (IS_ERR(cdev->tcdev))
> > + return PTR_ERR(cdev->tcdev);
> > +
> > + cdev->mcu_hwmon = mcu_hwmon;
> > + cdev->pwm_channel = pwm_channel;
> > +
> > + mcu_hwmon->cdev[pwm_channel] = cdev;
> > + }
> > + return 0;
> > +}
>
> --
> With Best Regards,
> Andy Shevchenko
I'll fix the issues you have mentioned above in the next patchset.
Kind regards,
Luka
next prev parent reply other threads:[~2020-10-23 21:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-19 22:18 [PATCH v6 0/6] Add support for the iEi WT61P803 PUZZLE MCU Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 1/6] dt-bindings: Add iEi vendor prefix and iEi WT61P803 PUZZLE driver bindings Luka Kovacic
2020-10-20 15:24 ` Rob Herring
2020-10-20 15:30 ` Rob Herring
2020-10-23 21:54 ` Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 2/6] drivers: mfd: Add a driver for iEi WT61P803 PUZZLE MCU Luka Kovacic
2020-10-20 2:19 ` kernel test robot
2020-11-04 15:22 ` Lee Jones
2020-11-10 20:14 ` Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 3/6] drivers: hwmon: Add the iEi WT61P803 PUZZLE HWMON driver Luka Kovacic
2020-10-20 9:00 ` Andy Shevchenko
2020-10-23 21:47 ` Luka Kovacic [this message]
2020-10-25 1:26 ` Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 4/6] drivers: leds: Add the iEi WT61P803 PUZZLE LED driver Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 5/6] Documentation/ABI: Add iei-wt61p803-puzzle driver sysfs interface documentation Luka Kovacic
2020-10-19 22:18 ` [PATCH v6 6/6] MAINTAINERS: Add an entry for the iEi WT61P803 PUZZLE driver Luka Kovacic
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='CADZsf3ZmeUZppsJaR7bT8y16L3Mj12tUfzo=hkV4nFgjN64Jqw@mail.gmail.com' \
--to=luka.kovacic@sartura.hr \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dmurphy@ti.com \
--cc=jdelvare@suse.com \
--cc=lee.jones@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=luka.perkov@sartura.hr \
--cc=marek.behun@nic.cz \
--cc=pavel@ucw.cz \
--cc=robert.marko@sartura.hr \
--cc=robh+dt@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).