Re: [PATCH 1/2] leds: Add flag to keep trigger always

From: Guru Das Srinagesh
Date: Fri Oct 04 2019 - 16:09:35 EST


On Mon, Sep 30, 2019 at 07:27:43PM +0200, Greg KH wrote:
> On Mon, Sep 30, 2019 at 07:22:39PM +0200, Pavel Machek wrote:
> > On Mon 2019-09-30 15:39:02, Greg KH wrote:
> > > On Sat, Aug 10, 2019 at 09:13:22AM +0200, Pavel Machek wrote:
> > > > On Fri 2019-08-09 17:52:46, Guru Das Srinagesh wrote:
> > > > > From: Subbaraman Narayanamurthy <subbaram@xxxxxxxxxxxxxx>
> > > > >
> > > > > Commit 0013b23d66a2768f5babbb0ea9f03ab067a990d8 ("leds: disable triggers
> > > > > on brightness set") removes the trigger on an LED class device when
> > > > > brightness is set to 0. However, there are some LED class devices which
> > > > > need the trigger not to be removed. In a use case like camera flash,
> > > > > camera flash driver passes in a trigger device to LED class driver. If
> > > > > the trigger is removed when the brightness is set to 0, this will affect
> > > > > the clients using those triggers. Hence add a flag to always keep the
> > > > > trigger even when brightness is set to 0.
> > > >
> > > > No.
> > > >
> > > > Yes, it would affect those clients. Don't do it, then. It is
> > > > root-only operation.
> > >
> > > I don't understand. The original commit broke userspace operations.
> > > Shouldn't it be reverted, or fixed this way in order to have userspace
> > > work properly again?
> >
> > So, what it is exactly that is not working? :-). Yes, root can
> > disconnect LED from v4l2 interface; he can also connect it
> > back. Documentation says that happens.
> >
> > Yes, root can do stupid things.
> >
> > Commit 0013b23d66a2768f5babbb0ea9f03ab067a990d8 is from 2008. I'd
> > prefer we did not apply it in 2008, but...
>
> Ah, my fault, I thought this was a new commit.
>
> Guru, what are you doing here that this is required all of a sudden? No
> other kernel seems to need these changes, what is different in your
> Android userspace that requires this patch series?
>
> thanks,
>
> greg k-h

Hi Greg,

Our camera flash driver first requests the available current from the
flash LED before setting its brightness. It passes a trigger as argument
to the function that determines the available current. This function
uses trigger_to_lcdev() to look up the led_classdev associated with that
trigger as a first step. This lookup will fail if the trigger has been
dissociated from its led_classdev as a result of a user setting that
led_classdev's brightness to zero manually through sysfs.

Why would the user set the brightness to zero? The user does this as
part of camera and LED testing activities which include, amongst other
things, visual inspection of the operation of various onboard LEDs. The
user uses sysfs to manually turn on and off the LEDs by setting their
brightness to max and then to zero in order to verify that they are
working as expected.

So what happens if the user, having turned off the flash LED after an
inspection, wishes to move on to testing the userspace camera app? The
userspace camera app will not be able to utilize the flash LED for any
of its functions due to the led_classdev lookup failure. The user has no
choice but to reboot the device to continue with his testing.

Therefore, to summarize, this patch is being utilized in our downstream
kernel (for a few years now) to support aforementioned testing
activities, and so we thought it might be a good idea to upstream this
patch now.