lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 28 Oct 2020 12:07:04 +0100
From:   Jacek Anaszewski <jacek.anaszewski@...il.com>
To:     ChiYuan Huang <u0084500@...il.com>
Cc:     Pavel Machek <pavel@....cz>, dmurphy@...com, robh+dt@...nel.org,
        linux-leds@...r.kernel.org, lkml <linux-kernel@...r.kernel.org>,
        cy_huang <cy_huang@...htek.com>, devicetree@...r.kernel.org
Subject: Re: [PATCH v1 1/2] leds: rt4505: Add support for Richtek RT4505 flash
 led controller

On 10/28/20 5:57 AM, ChiYuan Huang wrote:
> Hi,
> 
> Jacek Anaszewski <jacek.anaszewski@...il.com> 於 2020年10月28日 週三 上午12:40寫道:
>>
>> Hi Pavel, ChiYuan,
>>
>> On 10/27/20 9:29 AM, Pavel Machek wrote:
>>> Hi!
>>>
>>>> From: ChiYuan Huang <cy_huang@...htek.com>
>>>>
>>>> Add support for RT4505 flash led controller. It can support up to 1.5A
>>>> flash current with hardware timeout and low input voltage
>>>> protection.
>>>
>>> Please use upper-case "LED" everywhere.
>>>
>>> This should be 2nd in the series, after DT changes.
>>>
>>>> Signed-off-by: ChiYuan Huang <cy_huang@...htek.com>
>>>> ---
>>>>    drivers/leds/Kconfig       |  11 ++
>>>>    drivers/leds/Makefile      |   1 +
>>>>    drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++
>>>>    3 files changed, 409 insertions(+)
>>>>    create mode 100644 drivers/leds/leds-rt4505.c
>> [...]
>>>> +static int rt4505_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level)
>>>> +{
>>>
>>> 80 columns, where easy.
>>>
>>>> +    struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev);
>>>> +    u32 val = 0;
>>>> +    int ret;
>>>> +
>>>> +    mutex_lock(&priv->lock);
>>>> +
>>>> +    if (level != LED_OFF) {
>>>> +            ret = regmap_update_bits(priv->regmap, RT4505_REG_ILED, RT4505_ITORCH_MASK,
>>>> +                                     (level - 1) << RT4505_ITORCH_SHIFT);
>>>> +            if (ret)
>>>> +                    goto unlock;
>>>> +
>>>> +            val = RT4505_TORCH_SET;
>>>> +    }
>>>> +
>>>> +    ret = regmap_update_bits(priv->regmap, RT4505_REG_ENABLE, RT4505_ENABLE_MASK, val);
>>>> +
>>>> +unlock:
>>>> +    mutex_unlock(&priv->lock);
>>>> +    return ret;
>>>> +}
>>>
>>> Why is the locking needed? What will the /sys/class/leds interface
>>> look like on system with your flash?
>>
>> The locking is needed since this can be called via led_set_brightness()
>> from any place in the kernel, and especially from triggers.
>>>From this case, It means only led classdev
> brihtness_get/brightness_set need to be protected.
> I search led_flash_classdev, it only can be controlled via sysfs or V4l2.
> Like as described in last mail, flash related operation is protected
> by led access_lock and v4l2 framework.
> I'll keep the locking only in led classdev brightness_get/brightness_set API.
> If I misunderstand something, please help to point out.

Locking have to be used consistently for each access to the resource
being protected with the lock. Otherwise you can end up in a situation
when rt4505_torch_brightness_set and rt4505_flash_brightness_set will
try concurrently alter hardware state. Regardless of how harmful could
it be in case of this particular device it is certainly against
programming rules.

-- 
Best regards,
Jacek Anaszewski

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ