From: Matthias Kaehlcke <mka@chromium.org>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org,
chrome-platform@lists.linux.dev, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 5/5] platform/chrome: cros_kbd_led_backlight: support EC PWM backend
Date: Fri, 20 May 2022 08:29:19 -0700 [thread overview]
Message-ID: <YoezzzLdVfb0K7Ak@google.com> (raw)
In-Reply-To: <YocewB/lLJhIAuQP@google.com>
On Fri, May 20, 2022 at 12:53:20PM +0800, Tzung-Bi Shih wrote:
> On Thu, May 19, 2022 at 03:40:21PM -0700, Matthias Kaehlcke wrote:
> > On Mon, Mar 21, 2022 at 04:55:47PM +0800, Tzung-Bi Shih wrote:
> > > +struct keyboard_led_private {
> >
> > Why 'private', isn't this more a 'cros_ec_kdb_bl' or similar?
>
> It is just drvdata.
The data structure represents an instance of the device, as such it
is an important part of the driver, drvdata is just a way to attach
it to the platform device.
> I would prefer to keep the original prefix "keyboard_led_" if you wouldn't
> have strong opinion.
I'm fine with 'keyboard_led', but object to the 'private' part. In the
kernel 'private' fields are typically used when a driver consists of a
generic part and a device specific part. The driver has a 'private'
void* field that points to a device specific data structure about which
the generic driver is agnostic. This data structure is only used by the
device specific implementation. That isn't the case here, so naming the
structure anything 'private' is misleading.
> > > +static int
> > > +keyboard_led_set_brightness_blocking_ec_pwm(struct led_classdev *cdev,
> > > + enum led_brightness brightness)
> >
> > nit: since there is only a blocking version of .set_brightness you could omit
> > 'blocking' in the function name.
>
> Ack, will fix it in next version.
>
> > > + struct {
> > > + struct cros_ec_command msg;
> > > + struct ec_params_pwm_set_keyboard_backlight params;
> > > + } __packed buf;
> > > + struct ec_params_pwm_set_keyboard_backlight *params = &buf.params;
> > > + struct cros_ec_command *msg = &buf.msg;
> > > + struct keyboard_led_private *private =
Continuation of the argument above: the variable name 'private' doesn't
reveal anything about it's nature, something like 'kbd_led' would be much
clearer.
> > > + container_of(cdev, struct keyboard_led_private, cdev);
> > > +
> > > + memset(&buf, 0, sizeof(buf));
> > > +
> > > + msg->version = 0;
> >
> > not strictly needed since you do the memset above, I guess it's
> > fine to keep the assignment if you want to be explicit about the
> > version.
>
> Ack, let's remove them in next version.
>
> > > +static int keyboard_led_init_ec_pwm(struct platform_device *pdev)
> > > +{
> > > + struct keyboard_led_private *private = platform_get_drvdata(pdev);
> > > +
> > > + private->ec = dev_get_drvdata(pdev->dev.parent);
> > > + if (!private->ec) {
> > > + dev_err(&pdev->dev, "no parent EC device\n");
> > > + return -EINVAL;
> > > + }
> >
> > The only thing this 'init' function does is assigning private->ec. Wouldn't
> > it be clearer to do this directly in probe() from where callback is called?
> > It could be with the condition that the device as a DT node.
>
> No. The probe() isn't aware of the device is from ACPI or OF.
But it could be:
if (pdev->dev.of_node)
kbd_led->ec = dev_get_drvdata(pdev->dev.parent);
> > Is it actually possible that the keyboard backlight device gets instantiated
> > if there is no EC parent?
>
> It shouldn't be but just in case.
If this can only occur due to an error in common kernel frameworks then
the check should be omitted IMO.
> > > +static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm = {
> > > + .init = keyboard_led_init_ec_pwm_null,
> >
> > Is this really needed?
> >
> > keyboard_led_probe() checks if .init is assigned before invoking the callback:
> >
> > if (drvdata->init) {
> > error = drvdata->init(pdev);
> >
> > The whole 'else' branch could be eliminated if .of_match_table of the driver
> > only is assigned when CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM is set. IMO that
> > would preferable over creating 'stubs'.
>
> CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM and CONFIG_OF are independent. The stubs
> were created to avoid compile errors if CONFIG_OF=y but
> CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM=n.
Is there functional version of the driver that uses instantiation through the
device tree if CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM=n? If not .of_match_table
should not be assigned.
> However, I just realized it could also have compile errors if CONFIG_OF=n and
> CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM=y. The `keyboard_led_drvdata_ec_pwm` is
> unused.
>
> In any case, I agree with you. Let's remove the stubs in next version. I
> would use __maybe_unused for some of them.
next prev parent reply other threads:[~2022-05-20 15:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 8:55 [PATCH v3 0/5] platform/chrome: cros_kbd_led_backlight: add EC PWM backend Tzung-Bi Shih
2022-03-21 8:55 ` [PATCH v3 1/5] platform/chrome: cros_kbd_led_backlight: sort headers alphabetically Tzung-Bi Shih
2022-03-21 8:55 ` [PATCH v3 2/5] platform/chrome: cros_kbd_led_backlight: separate ACPI backend Tzung-Bi Shih
2022-03-21 8:55 ` [PATCH v3 3/5] dt-bindings: add google,cros-kbd-led-backlight Tzung-Bi Shih
2022-03-21 8:55 ` [PATCH v3 4/5] platform/chrome: cros_kbd_led_backlight: support OF match Tzung-Bi Shih
2022-05-19 22:49 ` Matthias Kaehlcke
2022-03-21 8:55 ` [PATCH v3 5/5] platform/chrome: cros_kbd_led_backlight: support EC PWM backend Tzung-Bi Shih
2022-05-19 22:40 ` Matthias Kaehlcke
2022-05-20 4:53 ` Tzung-Bi Shih
2022-05-20 15:29 ` Matthias Kaehlcke [this message]
2022-05-23 5:34 ` Tzung-Bi Shih
2022-05-24 19:52 ` Matthias Kaehlcke
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=YoezzzLdVfb0K7Ak@google.com \
--to=mka@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=devicetree@vger.kernel.org \
--cc=groeck@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=tzungbi@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).