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: <CAEc3jaBvsr5vnc_Dfm2YsThxBr94TkE3i16GLQipVZM+4KH3cw@mail.gmail.com>
Date: Wed, 24 Jan 2024 17:01:00 -0800
From: Roderick Colenbrander <thunderbird2k@...il.com>
To: Max Staudt <max@...as.org>
Cc: Roderick Colenbrander <roderick.colenbrander@...y.com>, Jiri Kosina <jikos@...nel.org>, 
	Benjamin Tissoires <benjamin.tissoires@...hat.com>, linux-input@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 6/7] HID: playstation: Simplify device type ID

On Mon, Jan 15, 2024 at 6:55 AM Max Staudt <max@...as.org> wrote:
>
> Distinguish PS4/PS5 type controllers using .driver_data in
> MODULE_DEVICE_TABLE rather than by VID/PID.
>
> This allows adding compatible controllers with different VID/PID.
>
> Signed-off-by: Max Staudt <max@...as.org>
> ---
>  drivers/hid/hid-playstation.c | 40 +++++++++++++++++++++++------------
>  1 file changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 086b0768fa51..a0eb36d695d9 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -27,6 +27,11 @@ static DEFINE_IDA(ps_player_id_allocator);
>
>  #define HID_PLAYSTATION_VERSION_PATCH 0x8000
>
> +enum PS_TYPE {
> +       PS_TYPE_PS4_DUALSHOCK4,
> +       PS_TYPE_PS5_DUALSENSE,
> +};
> +
>  /* Base class for playstation devices. */
>  struct ps_device {
>         struct list_head list;
> @@ -2690,17 +2695,14 @@ static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id)
>                 goto err_stop;
>         }
>
> -       if (hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER ||
> -               hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER_2 ||
> -               hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) {
> +       if (id->driver_data == PS_TYPE_PS4_DUALSHOCK4) {
>                 dev = dualshock4_create(hdev);
>                 if (IS_ERR(dev)) {
>                         hid_err(hdev, "Failed to create dualshock4.\n");
>                         ret = PTR_ERR(dev);
>                         goto err_close;
>                 }
> -       } else if (hdev->product == USB_DEVICE_ID_SONY_PS5_CONTROLLER ||
> -               hdev->product == USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) {
> +       } else if (id->driver_data == PS_TYPE_PS5_DUALSENSE) {
>                 dev = dualsense_create(hdev);
>                 if (IS_ERR(dev)) {
>                         hid_err(hdev, "Failed to create dualsense.\n");
> @@ -2734,16 +2736,26 @@ static void ps_remove(struct hid_device *hdev)
>
>  static const struct hid_device_id ps_devices[] = {
>         /* Sony DualShock 4 controllers for PS4 */
> -       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
> -       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
> -       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
> -       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
> -       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) },
> +       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
> +               .driver_data = PS_TYPE_PS4_DUALSHOCK4 },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
> +               .driver_data = PS_TYPE_PS4_DUALSHOCK4 },
> +       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2),
> +               .driver_data = PS_TYPE_PS4_DUALSHOCK4 },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2),
> +               .driver_data = PS_TYPE_PS4_DUALSHOCK4 },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE),
> +               .driver_data = PS_TYPE_PS4_DUALSHOCK4 },
> +
>         /* Sony DualSense controllers for PS5 */
> -       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
> -       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
> -       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) },
> -       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2) },
> +       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER),
> +               .driver_data = PS_TYPE_PS5_DUALSENSE },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER),
> +               .driver_data = PS_TYPE_PS5_DUALSENSE },
> +       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2),
> +               .driver_data = PS_TYPE_PS5_DUALSENSE },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER_2),
> +               .driver_data = PS_TYPE_PS5_DUALSENSE },
>         { }
>  };
>  MODULE_DEVICE_TABLE(hid, ps_devices);
> --
> 2.39.2
>
>

Hi Max,

This one looks good to me.

Roderick

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ