From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
Cc: "Jiri Kosina" <jikos@kernel.org>,
"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
"Pierre-Loup A. Griffais" <pgriffais@valvesoftware.com>,
"Cameron Gutman" <aicommander@gmail.com>,
"Clément VUCHENER" <clement.vuchener@gmail.com>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
linux-input <linux-input@vger.kernel.org>
Subject: Re: [PATCH v4 1/4] HID: add driver for Valve Steam Controller
Date: Thu, 1 Mar 2018 12:20:37 +0200 [thread overview]
Message-ID: <CAHp75Vd9wgX8S=4hGFERN5bEN9q4=DxYcDea9Z=mvSRi2GcxeQ@mail.gmail.com> (raw)
In-Reply-To: <20180228224926.GA7009@casa>
On Thu, Mar 1, 2018 at 12:49 AM, Rodrigo Rivas Costa
<rodrigorivascosta@gmail.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@gmail.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
next prev parent reply other threads:[~2018-03-01 10:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-28 18:43 [PATCH v4 0/4] new driver for Valve Steam Controller Rodrigo Rivas Costa
2018-02-28 18:43 ` [PATCH v4 1/4] HID: add " Rodrigo Rivas Costa
2018-02-28 19:21 ` Andy Shevchenko
2018-02-28 22:49 ` Rodrigo Rivas Costa
2018-03-01 7:50 ` Marcus Folkesson
2018-03-01 10:20 ` Andy Shevchenko [this message]
2018-03-01 19:13 ` Rodrigo Rivas Costa
2018-03-01 19:57 ` Andy Shevchenko
2018-02-28 18:43 ` [PATCH v4 2/4] HID: steam: add serial number information Rodrigo Rivas Costa
2018-02-28 20:17 ` Andy Shevchenko
2018-02-28 23:12 ` Rodrigo Rivas Costa
2018-02-28 18:43 ` [PATCH v4 3/4] HID: steam: command to check wireless connection Rodrigo Rivas Costa
2018-02-28 18:43 ` [PATCH v4 4/4] HID: steam: add battery device Rodrigo Rivas Costa
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='CAHp75Vd9wgX8S=4hGFERN5bEN9q4=DxYcDea9Z=mvSRi2GcxeQ@mail.gmail.com' \
--to=andy.shevchenko@gmail.com \
--cc=aicommander@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=clement.vuchener@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pgriffais@valvesoftware.com \
--cc=rodrigorivascosta@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).