Re: [PATCH 3/5] HID: dualsense_remove: manually unregister leds

From: Roderick Colenbrander
Date: Wed Jan 25 2023 - 19:47:22 EST


One other little note. For completeness I guess we need a similar
patch for the multicolor led class.

On Wed, Jan 25, 2023 at 4:43 PM Roderick Colenbrander
<thunderbird2k@xxxxxxxxx> wrote:
>
> Hi Pietro,
>
> Thanks for your patch. For sure for ds4/dualsense there have been edge
> cases around rumble removal and others. Those were prevented by this
> 'output_worker_initialized' variable, which is checked during the
> centralized work scheduling function (dualshock4_schedule_work /
> dualsense_schedule_work). That said I don't mind the change as it
> prevents the work scheduling functions to get called unnecessarily.
>
> Thanks,
> Roderick Colenbrander
>
> On Wed, Jan 25, 2023 at 4:26 PM Pietro Borrello
> <borrello@xxxxxxxxxxxxxxxx> wrote:
> >
> > Unregister the LED controller before device removal, as
> > dualsense_player_led_set_brightness() may schedule output_worker
> > after the structure has been freed, causing a use-after-free.
> >
> > Fixes: 8c0ab553b072 ("HID: playstation: expose DualSense player LEDs through LED class.")
> > Signed-off-by: Pietro Borrello <borrello@xxxxxxxxxxxxxxxx>
> > ---
> > drivers/hid/hid-playstation.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> > index 27c40894acab..9e23860b7e95 100644
> > --- a/drivers/hid/hid-playstation.c
> > +++ b/drivers/hid/hid-playstation.c
> > @@ -1503,11 +1503,15 @@ static void dualsense_remove(struct ps_device *ps_dev)
> > {
> > struct dualsense *ds = container_of(ps_dev, struct dualsense, base);
> > unsigned long flags;
> > + int i;
> >
> > spin_lock_irqsave(&ds->base.lock, flags);
> > ds->output_worker_initialized = false;
> > spin_unlock_irqrestore(&ds->base.lock, flags);
> >
> > + for (i = 0; i < ARRAY_SIZE(ds->player_leds); i++)
> > + devm_led_classdev_unregister(&ps_dev->hdev->dev, &ds->player_leds[i]);
> > +
> > cancel_work_sync(&ds->output_worker);
> > }
> >
> >
> > --
> > 2.25.1