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]
Message-ID: <CAHp75Vd9wgX8S=4hGFERN5bEN9q4=DxYcDea9Z=mvSRi2GcxeQ@mail.gmail.com>
Date:   Thu, 1 Mar 2018 12:20:37 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Rodrigo Rivas Costa <rodrigorivascosta@...il.com>
Cc:     Jiri Kosina <jikos@...nel.org>,
        Benjamin Tissoires <benjamin.tissoires@...hat.com>,
        "Pierre-Loup A. Griffais" <pgriffais@...vesoftware.com>,
        Cameron Gutman <aicommander@...il.com>,
        Clément VUCHENER <clement.vuchener@...il.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-input <linux-input@...r.kernel.org>
Subject: Re: [PATCH v4 1/4] HID: add driver for Valve Steam Controller

On Thu, Mar 1, 2018 at 12:49 AM, Rodrigo Rivas Costa
<rodrigorivascosta@...il.com> wrote:
> On Wed, Feb 28, 2018 at 09:21:15PM +0200, Andy Shevchenko wrote:
>> On Wed, Feb 28, 2018 at 8:43 PM, Rodrigo Rivas Costa
>> <rodrigorivascosta@...il.com> wrote:

>> > +       if (input) {
>>
>> if (!input)
>>  return;
>>
>> ?
> That was because of symmetry, because further patches add more objects.
> Then
> if (input)
>         free(input);
> if (battery)
>         free(battery);
> /* in the future *(
> if (input_gyro)
>         free(input_gyro);
>
> Sure, the last one can do an early return, but you break symmetry.

The generic APIs when designed properly are NULL aware at freeing resources.

So, it should look like

free(input);
free(battery);
free(input_gyro);


>> > +       if (steam) {
>> > +               cancel_work_sync(&steam->work_connect);
>> > +               steam_unregister(steam);
>>
>> > +               hid_set_drvdata(hdev, NULL);
>>
>> Hmm.. Doesn't HID do this?
>
> Do you mean the hid_set_drvdata(hdev, NULL)? I'm not sure, I didn't see
> that on hid-core.c or hid-generic.c. And a call like this is done in
> many modules... so I did the same, just to be sure.

What you are looking for is, AFAIU:

drivers/base/dd.c:902:          dev_set_drvdata(dev, NULL);


>>
>> > +       }
>>
>> if (steam) {
>> ...
>>        hid_hw_stop(hdev);
>> ...
>> } else {
>>        hid_hw_stop(hdev);
>> }
>>
>> ?
>
> I have no real preference. Your version has two 'if', mine has two 'if'.
> What about:
>
> static void steam_remove(struct hid_device *hdev)
> {
>         struct steam_device *steam = hid_get_drvdata(hdev);
>
>         if (!steam) {
>                 hid_hw_stop(hdev);
>                 return;
>         }
>
>         if (steam->quirks & STEAM_QUIRK_WIRELESS) {
>                 hid_info(hdev, "Steam wireless receiver disconnected");
>                 hid_hw_close(hdev);
>         }
>         hid_hw_stop(hdev);
>         cancel_work_sync(&steam->work_connect);
>         steam_unregister(steam);

>         hid_set_drvdata(hdev, NULL);

w/o this one.

> }

For me my version looks more compact to read, but at the end it's up to you.
Another option split if (steam) variant into helper, and thus

if (steam)
 steam_non_null_device_remove();
else
 hid_hw_stop();

But again, up to you (that's why question mark in the first place above).

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ