Re: [PATCH v4 1/4] HID: add driver for Valve Steam Controller
From: Andy Shevchenko <hidden>
Date: 2018-03-01 10:20:43
Also in:
lkml
On Thu, Mar 1, 2018 at 12:49 AM, Rodrigo Rivas Costa [off-list ref] wrote:
On Wed, Feb 28, 2018 at 09:21:15PM +0200, Andy Shevchenko wrote:quoted
On Wed, Feb 28, 2018 at 8:43 PM, Rodrigo Rivas Costa [off-list ref] wrote:
quoted
quoted
+ 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);
quoted
quoted
+ if (steam) { + cancel_work_sync(&steam->work_connect); + steam_unregister(steam);quoted
+ 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);
quoted
quoted
+ }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