From: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
To: Lee Jones <lee@kernel.org>
Cc: <lee.jones@linaro.org>, <pavel@ucw.cz>,
<linux-leds@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 6/6] leds: Add a multicolor LED driver to group monochromatic LEDs
Date: Tue, 28 Mar 2023 17:31:36 +0200 [thread overview]
Message-ID: <d1771420-b45e-3ce1-f469-bc5fd9ab6dfa@traphandler.com> (raw)
In-Reply-To: <20230315155241.GA9667@google.com>
On 15/03/2023 16:52, Lee Jones wrote:
>> + for (;;) {
>> + struct led_classdev *led_cdev;
>> +
>> + led_cdev = devm_of_led_get_optional(dev, count);
>> + if (IS_ERR(led_cdev))
>
> Doesn't devm_of_led_get_optional() return NULL on failure?
Hi Lee,
Thanks for you review. I'll send an updated version shortly.
devm_of_led_get_optional() return an error-pointer when it cannot get
the LED (like EPROBE_DEFER or ENOMEM). When the LED is not defined, it
returns NULL.
>
>> + return dev_err_probe(dev, PTR_ERR(led_cdev),
>> + "Unable to get led #%d", count);
>> + /* Reached the end of the list ?*/
>
> Besides the incorrect formatting, that '?' isn't filling me with
> confidence.
The comment just meant that NULL indicates the end of the list of the LEDs.
JJ
>
>> + if (!led_cdev)
>> + break;
>> +
>> + priv->monochromatics = devm_krealloc_array(dev, priv->monochromatics,
>> + count + 1, sizeof(*priv->monochromatics),
>> + GFP_KERNEL);
>> + if (!priv->monochromatics)
>> + return -ENOMEM;
>> +
>> + priv->monochromatics[count] = led_cdev;
>> +
>> + max_brightness = max(max_brightness, led_cdev->max_brightness);
>> + count++;
>> + }
>> +
>> + subled = devm_kcalloc(dev, count, sizeof(*subled), GFP_KERNEL);
>> + if (!subled)
>> + return -ENOMEM;
>> + priv->mc_cdev.subled_info = subled;
>> +
>> + for (i = 0; i < count; i++) {
>> + struct led_classdev *led_cdev = priv->monochromatics[i];
>> +
>> + subled[i].color_index = led_cdev->color;
>
> '\n'
>
>> + /* configure the LED intensity to its maximum */
>
> Use correct grammar in comments please.
>
> Start with an uppercase char.
>
>> + subled[i].intensity = max_brightness;
>> + }
>> +
>> + /* init the multicolor's LED class device */
>
> As above and please be fully forthcoming in comments: "Initialise".
>
>> + cdev = &priv->mc_cdev.led_cdev;
>> + cdev->flags = LED_CORE_SUSPENDRESUME;
>> + cdev->brightness_set_blocking = led_mcg_set;
>> + cdev->max_brightness = max_brightness;
>> + cdev->color = LED_COLOR_ID_MULTI;
>> + priv->mc_cdev.num_colors = count;
>> +
>> + init_data.fwnode = dev_fwnode(dev);
>> + ret = devm_led_classdev_multicolor_register_ext(dev, &priv->mc_cdev,
>> + &init_data);
>
> Use the full 100-char limit everywhere please.
>
>> + if (ret)
>> + return dev_err_probe(dev, ret,
>> + "failed to register multicolor led for %s.\n",
>
> "LED"
>
>> + cdev->name);
>> +
>> + ret = led_mcg_set(cdev, cdev->brightness);
>> + if (ret)
>> + return dev_err_probe(dev, ret,
>> + "failed to set led value for %s.",
>> + cdev->name);
>> +
>> + for (i = 0; i < count; i++) {
>> + struct led_classdev *led_cdev = priv->monochromatics[i];
>> +
>> + /* Make the sysfs of the monochromatic LED read-only */
>> + mutex_lock(&led_cdev->led_access);
>> + led_sysfs_disable(led_cdev);
>> + mutex_unlock(&led_cdev->led_access);
>> +
>> + /* Restore sysfs access when the multicolor LED is released */
>> + devm_add_action_or_reset(dev, restore_sysfs_access, led_cdev);
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static const struct of_device_id of_led_mcg_match[] = {
>> + { .compatible = "leds-group-multicolor" },
>> + {}
>> +};
>> +MODULE_DEVICE_TABLE(of, of_led_mcg_match);
>> +
>> +static struct platform_driver led_mcg_driver = {
>> + .probe = led_mcg_probe,
>> + .driver = {
>> + .name = "leds_group_multicolor",
>> + .of_match_table = of_led_mcg_match,
>> + }
>> +};
>> +module_platform_driver(led_mcg_driver);
>> +
>> +MODULE_AUTHOR("Jean-Jacques Hiblot <jjhiblot@traphandler.com>");
>> +MODULE_DESCRIPTION("multi-color LED group driver");
>> +MODULE_LICENSE("GPL");
>> +MODULE_ALIAS("platform:leds-group-multicolor");
>> --
>> 2.25.1
>>
>
> --
> Lee Jones [李琼斯]
next prev parent reply other threads:[~2023-03-28 15:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-02 8:10 [PATCH v7 0/6] Add a multicolor LED driver for groups of " Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 1/6] devres: provide devm_krealloc_array() Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 2/6] leds: class: simplify the implementation of devm_of_led_get() Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 3/6] leds: provide devm_of_led_get_optional() Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 4/6] leds: class: store the color index in struct led_classdev Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 5/6] dt-bindings: leds: Add binding for a multicolor group of LEDs Jean-Jacques Hiblot
2023-01-02 8:10 ` [PATCH v7 6/6] leds: Add a multicolor LED driver to group monochromatic LEDs Jean-Jacques Hiblot
2023-03-15 15:52 ` Lee Jones
2023-03-28 15:31 ` Jean-Jacques Hiblot [this message]
2023-01-09 17:19 ` [PATCH v7 0/6] Add a multicolor LED driver for groups of " Lee Jones
2023-02-20 21:10 ` Jean-Jacques Hiblot
2023-02-22 15:04 ` Lee Jones
2023-03-15 15:53 ` Lee Jones
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=d1771420-b45e-3ce1-f469-bc5fd9ab6dfa@traphandler.com \
--to=jjhiblot@traphandler.com \
--cc=lee.jones@linaro.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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
all inboxes | Powered by JetHome®