From nobody Fri Jun 19 22:18:44 2026 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B82D8395D8F; Tue, 16 Jun 2026 20:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643083; cv=none; b=tf+QQKxG+4rcJummeEene/f1Rf4MHAJXKWyGgg7G8i/EI+7ARqEEb94eZwuKIkFQPGoykA7zm9L/nN7jjOwgGLyrc9F4u2FHxA9TcT94tjDijM3tZNIZJletKI0lg/bybc6E6REtklSJN4ucTGOoLoAmWwf0AGU0iI8myReyHyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643083; c=relaxed/simple; bh=pu4j2dY2zpxgvt0XMie3WYT7gkv2xrDM0YpHdtW0LE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q74s45FoCh6n021YFSxeOyIXTppJ9Lldp+TIFiZThfqZASM1tiBLnJmjAzfH9DeGsDVEgVwgI/u/RGhLAc07cWia4NVoN6Ic7D4Ur9S9CJZFpp3puZpXN0+AuVRCFnXfMKys7f6qp2vVDae9gube6hR0Bd6eTUm2xYr6QANwzgs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=Uj7t7WiY; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=YigwUk4Q; arc=none smtp.client-ip=80.241.56.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="Uj7t7WiY"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="YigwUk4Q" Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4gfzfs64XVz9tqr; Tue, 16 Jun 2026 22:51:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qb15gxayLUlnZzkIcUaLU5oNhS1Zw1hF9L1qbN15QT0=; b=Uj7t7WiYKQ11m5Dw//RWuCU6K7ESznwUCWeJ74tOpXK6MibCzUNE4R+QwygoyXjfCgqBxz RHXDLMJw2sMtLnF0thLypZ4umflPjwHsyO1gDn5BOMb9FaDenMig6tbAKCRuHqYA4bNdNs Bx5o20FhNoLiDIfya6OS76t4jL9xAe509O11EzyW4VFwFyTw5wQ2U8vcEjCX00DUpHm9iT gsc1KFJ0Eci+97KjRCMoOafmlox5slESckisDMkBRbZwceGNFuovSV3PQPD5qC9pHEFYQz eS847ZTzAFpga4O3kPaJp5BMHNZlyAh0Qfg0qHNjWBGITCPtjE4WQO+cw11TAg== From: Rosalie Wanders DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qb15gxayLUlnZzkIcUaLU5oNhS1Zw1hF9L1qbN15QT0=; b=YigwUk4Q/bBMITxDdw1Q5+5X1PrcoYhYg3vWviZx1klCe9zeMDPUaotOxshlFsRp9pHa0D aa0m2nWYs5iYiGARCRVrUtx0r2zU86+F2pjWrCKlaOnfiCN50fjQgP9puuKBZeKNO0IxJR lnzXzPHaZcmYPyA6KosAWnoeP+K758u7U6MiQ8HXat2ZUGJR2PbpVIw6J+FjNHC9Ry2Sx+ SSoi/GH+xkkLz6pCHw/Z3cywkK2OT8Y6yBDWGA4ZurH/fYo0Dvhw7/9AfzuMsUZ0zlZwER tInlv3/t2jpO8T9aG2QIkUdfhDO2J0Dyu2qRWMFs2+UlKM/udUEuehJEsQYlPg== To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rosalie Wanders Subject: [PATCH v2 1/4] HID: sony: use dedicated raw_event() handlers in sony_raw_event() Date: Tue, 16 Jun 2026 22:50:40 +0200 Message-ID: <20260616205042.6671-3-rosalie@mailbox.org> In-Reply-To: <20260616205042.6671-2-rosalie@mailbox.org> References: <20260616205042.6671-2-rosalie@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: yhsacco9udjj7uy93sjauzsjhganskpq X-MBO-RS-ID: 8531d1f15150de31b27 Content-Type: text/plain; charset="utf-8" This commit changes the way sony_raw_event() works by adding a function pointer to a raw_event() handler in the sc struct instead of manually checking the quirk in order to call the right function, this simplifies the sony_raw_event() function alongside making the raw_event() handlers more self-contained, thus making the code more readable. The raw_event() handler should be configured using the new sony_init_raw_event_handler() function in sony_input_configured(), where we already check for quirks and apply device specific workarounds. Signed-off-by: Rosalie Wanders --- drivers/hid/hid-sony.c | 145 +++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 55 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index e75246d29e16..2d9a5261b63f 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -81,6 +81,7 @@ #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER) #define SONY_BT_DEVICE (SIXAXIS_CONTROLLER_BT | MOTION_CONTROLLER_BT | NAV= IGATION_CONTROLLER_BT) #define NSG_MRXU_REMOTE (NSG_MR5U_REMOTE_BT | NSG_MR7U_REMOTE_BT) +#define RB4_GUITAR_PS4 (RB4_GUITAR_PS4_USB | RB4_GUITAR_PS4_BT) =20 #define MAX_LEDS 4 #define NSG_MRXU_MAX_X 1667 @@ -534,6 +535,7 @@ struct sony_sc { struct input_dev *sensor_dev; struct led_classdev *leds[MAX_LEDS]; unsigned long quirks; + int (*raw_event)(struct sony_sc *sc, u8 *rd, int size); struct work_struct state_worker; void (*send_output_report)(struct sony_sc *sc); struct power_supply *battery; @@ -946,7 +948,7 @@ static const u8 *sony_report_fixup(struct hid_device *h= dev, u8 *rdesc, return rdesc; } =20 -static void sixaxis_parse_report(struct sony_sc *sc, u8 *rd, int size) +static int sixaxis_raw_event(struct sony_sc *sc, u8 *rd, int size) { static const u8 sixaxis_battery_capacity[] =3D { 0, 1, 25, 50, 75, 100 }; unsigned long flags; @@ -955,6 +957,31 @@ static void sixaxis_parse_report(struct sony_sc *sc, u= 8 *rd, int size) u8 battery_capacity; int battery_status; =20 + if (unlikely(size !=3D 49 || rd[0] !=3D 0x01)) + return 0; + + if (sc->quirks & SIXAXIS_CONTROLLER) { + /* + * When connected via Bluetooth the Sixaxis occasionally sends + * a report with the second byte 0xff and the rest zeroed. + * + * This report does not reflect the actual state of the + * controller must be ignored to avoid generating false input + * events. + */ + if (rd[1] =3D=3D 0xff) + return -EINVAL; + + /* + * Sixaxis HID report has acclerometers/gyro with MSByte first, this + * has to be BYTE_SWAPPED before passing up to joystick interface + */ + swap(rd[41], rd[42]); + swap(rd[43], rd[44]); + swap(rd[45], rd[46]); + swap(rd[47], rd[48]); + } + /* * The sixaxis is charging if the battery value is 0xee * and it is fully charged if the value is 0xef. @@ -993,13 +1020,18 @@ static void sixaxis_parse_report(struct sony_sc *sc,= u8 *rd, int size) =20 input_sync(sc->sensor_dev); } + + return 0; } =20 -static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size) +static int nsg_mrxu_raw_event(struct sony_sc *sc, u8 *rd, int size) { int n, offset, relx, rely; u8 active; =20 + if (unlikely(size < 12 || rd[0] !=3D 0x02)) + return 0; + /* * The NSG-MRxU multi-touch trackpad data starts at offset 1 and * the touch-related data starts at offset 2. @@ -1067,10 +1099,33 @@ static void nsg_mrxu_parse_report(struct sony_sc *s= c, u8 *rd, int size) input_mt_sync_frame(sc->touchpad); =20 input_sync(sc->touchpad); + return 0; +} + +static int rb3_pro_instrument_raw_event(struct sony_sc *sc, u8 *rd, int si= ze) +{ + /* Rock Band 3 PS3 Pro instruments set rd[24] to 0xE0 when they're + * sending full reports, and 0x02 when only sending navigation. + */ + if (size < 25 || rd[24] !=3D 0x02) + return 0; + + /* Only attempt to enable full report every 8 seconds */ + if (time_after(jiffies, sc->rb3_pro_poke_jiffies)) { + sc->rb3_pro_poke_jiffies =3D jiffies + secs_to_jiffies(8); + rb3_pro_instrument_enable_full_report(sc); + } + + return 0; } =20 -static void rb4_ps4_guitar_parse_report(struct sony_sc *sc, u8 *rd, int si= ze) +static int rb4_ps4_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size) { + const int expected_size =3D (sc->quirks & RB4_GUITAR_PS4_BT) ? 78 : 64; + + if (unlikely(size !=3D expected_size || rd[0] !=3D 0x01)) + return 0; + /* * Rock Band 4 PS4 guitars have whammy and * tilt functionality, they're located at @@ -1084,9 +1139,10 @@ static void rb4_ps4_guitar_parse_report(struct sony_= sc *sc, u8 *rd, int size) input_report_abs(sc->input_dev, ABS_RZ, rd[45]); =20 input_sync(sc->input_dev); + return 0; } =20 -static void rb4_ps5_guitar_parse_report(struct sony_sc *sc, u8 *rd, int si= ze) +static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size) { u8 charging_status; u8 battery_data; @@ -1094,6 +1150,9 @@ static void rb4_ps5_guitar_parse_report(struct sony_s= c *sc, u8 *rd, int size) u8 battery_status; unsigned long flags; =20 + if (unlikely(size !=3D 64 || rd[0] !=3D 0x01)) + return 0; + /* * Rock Band 4 PS5 guitars have whammy and * tilt functionality, they're located at @@ -1138,65 +1197,22 @@ static void rb4_ps5_guitar_parse_report(struct sony= _sc *sc, u8 *rd, int size) spin_unlock_irqrestore(&sc->lock, flags); =20 input_sync(sc->input_dev); + return 0; } =20 static int sony_raw_event(struct hid_device *hdev, struct hid_report *repo= rt, u8 *rd, int size) { struct sony_sc *sc =3D hid_get_drvdata(hdev); + int ret; =20 - /* - * Sixaxis HID report has acclerometers/gyro with MSByte first, this - * has to be BYTE_SWAPPED before passing up to joystick interface - */ - if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] =3D=3D 0x01 && size =3D=3D= 49) { - /* - * When connected via Bluetooth the Sixaxis occasionally sends - * a report with the second byte 0xff and the rest zeroed. - * - * This report does not reflect the actual state of the - * controller must be ignored to avoid generating false input - * events. - */ - if (rd[1] =3D=3D 0xff) - return -EINVAL; - - swap(rd[41], rd[42]); - swap(rd[43], rd[44]); - swap(rd[45], rd[46]); - swap(rd[47], rd[48]); - - sixaxis_parse_report(sc, rd, size); - } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] =3D=3D 0x01 && si= ze =3D=3D 49) { - sixaxis_parse_report(sc, rd, size); - } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] =3D=3D 0x01 && s= ize =3D=3D 49) { - sixaxis_parse_report(sc, rd, size); - } else if ((sc->quirks & NSG_MRXU_REMOTE) && rd[0] =3D=3D 0x02 && size >= =3D 12) { - nsg_mrxu_parse_report(sc, rd, size); - return 1; - } else if ((sc->quirks & RB4_GUITAR_PS4_USB) && rd[0] =3D=3D 0x01 && size= =3D=3D 64) { - rb4_ps4_guitar_parse_report(sc, rd, size); - return 1; - } else if ((sc->quirks & RB4_GUITAR_PS4_BT) && rd[0] =3D=3D 0x01 && size = =3D=3D 78) { - rb4_ps4_guitar_parse_report(sc, rd, size); - return 1; - } else if ((sc->quirks & RB4_GUITAR_PS5) && rd[0] =3D=3D 0x01 && size =3D= =3D 64) { - rb4_ps5_guitar_parse_report(sc, rd, size); - return 1; - } - - /* Rock Band 3 PS3 Pro instruments set rd[24] to 0xE0 when they're - * sending full reports, and 0x02 when only sending navigation. - */ - if ((sc->quirks & RB3_PRO_INSTRUMENT) && size >=3D 25 && rd[24] =3D=3D 0x= 02) { - /* Only attempt to enable full report every 8 seconds */ - if (time_after(jiffies, sc->rb3_pro_poke_jiffies)) { - sc->rb3_pro_poke_jiffies =3D jiffies + secs_to_jiffies(8); - rb3_pro_instrument_enable_full_report(sc); - } + if (sc->raw_event) { + ret =3D sc->raw_event(sc, rd, size); + if (unlikely(ret < 0)) + return ret; } =20 - if (sc->defer_initialization) { + if (unlikely(sc->defer_initialization)) { sc->defer_initialization =3D 0; sony_schedule_work(sc, SONY_WORKER_STATE); } @@ -1256,7 +1272,7 @@ static int sony_mapping(struct hid_device *hdev, stru= ct hid_input *hi, if (sc->quirks & DJH_TURNTABLE) return djh_turntable_mapping(hdev, hi, field, usage, bit, max); =20 - if (sc->quirks & (RB4_GUITAR_PS4_USB | RB4_GUITAR_PS4_BT)) + if (sc->quirks & RB4_GUITAR_PS4) return rb4_guitar_mapping(hdev, hi, field, usage, bit, max); =20 if (sc->quirks & RB4_GUITAR_PS5) @@ -2110,6 +2126,12 @@ static void sony_release_device_id(struct sony_sc *s= c) } } =20 +static inline void sony_init_raw_event_handler(struct sony_sc *sc, + int (*raw_event)(struct sony_sc *, u8 *, int)) +{ + sc->raw_event =3D raw_event; +} + static inline void sony_init_output_report(struct sony_sc *sc, void (*send_output_report)(struct sony_sc *)) { @@ -2185,6 +2207,7 @@ static int sony_input_configured(struct hid_device *h= dev, goto err_stop; } =20 + sony_init_raw_event_handler(sc, sixaxis_raw_event); sony_init_output_report(sc, sixaxis_send_output_report); } else if (sc->quirks & NAVIGATION_CONTROLLER_BT) { /* @@ -2199,6 +2222,7 @@ static int sony_input_configured(struct hid_device *h= dev, goto err_stop; } =20 + sony_init_raw_event_handler(sc, sixaxis_raw_event); sony_init_output_report(sc, sixaxis_send_output_report); } else if (sc->quirks & RB3_PRO_INSTRUMENT) { /* @@ -2213,6 +2237,8 @@ static int sony_input_configured(struct hid_device *h= dev, */ hdev->quirks |=3D HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; hdev->quirks |=3D HID_QUIRK_SKIP_OUTPUT_REPORT_ID; + + sony_init_raw_event_handler(sc, rb3_pro_instrument_raw_event); } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) { /* * The Sony Sixaxis does not handle HID Output Reports on the @@ -2237,6 +2263,7 @@ static int sony_input_configured(struct hid_device *h= dev, goto err_stop; } =20 + sony_init_raw_event_handler(sc, sixaxis_raw_event); sony_init_output_report(sc, sixaxis_send_output_report); } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) { /* @@ -2258,6 +2285,7 @@ static int sony_input_configured(struct hid_device *h= dev, goto err_stop; } =20 + sony_init_raw_event_handler(sc, sixaxis_raw_event); sony_init_output_report(sc, sixaxis_send_output_report); } else if (sc->quirks & NSG_MRXU_REMOTE) { /* @@ -2273,8 +2301,15 @@ static int sony_input_configured(struct hid_device *= hdev, goto err_stop; } =20 + sony_init_raw_event_handler(sc, nsg_mrxu_raw_event); } else if (sc->quirks & MOTION_CONTROLLER) { + if (sc->quirks & MOTION_CONTROLLER_BT) + sony_init_raw_event_handler(sc, sixaxis_raw_event); sony_init_output_report(sc, motion_send_output_report); + } else if (sc->quirks & RB4_GUITAR_PS4) { + sony_init_raw_event_handler(sc, rb4_ps4_guitar_raw_event); + } else if (sc->quirks & RB4_GUITAR_PS5) { + sony_init_raw_event_handler(sc, rb4_ps5_guitar_raw_event); } =20 if (sc->quirks & SONY_LED_SUPPORT) { --=20 2.54.0 From nobody Fri Jun 19 22:18:44 2026 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F027839A7F2; Tue, 16 Jun 2026 20:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643088; cv=none; b=CAh5F+99TDxyV27WBgIzA5hKlu7q63LNxmCP7FNxQGq4MHxMa0psY6MoR/5yH/qahOlxu0rRBL4nYx+cL/ESiix4FRa4EiYNBGgUD0e8N4InA3dELErtLnGOHcGGPdYpflePtaHLYKB3k4Mqdp3QKdRhYb8FroS29v7GfFkKtFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643088; c=relaxed/simple; bh=MbHsw42samx2xH/ZKW+PoB6rmQm91u1z7BybUDOTVuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vtiu5s0PxjTl1SMNddvwh3OWl/0rNWWUJGuFCdZuZKc+fPVPhpkqFmvOTZB84QTgjNiYDebgIqSovBr8sFlzjByALWg6QfjW8ZNKMWjvSrO4tXShp5gZ5mPWksGf3CG8jK3y+sgtebz4XEWm1NzkBSr/MmN/QkNjnQRlbYuxQuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=hNinVss/; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=pQYYykm9; arc=none smtp.client-ip=80.241.56.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="hNinVss/"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="pQYYykm9" Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4gfzfx6F4Zz9twZ; Tue, 16 Jun 2026 22:51:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/sbe5AapSrG6r3iBm0A/wH45Y9WOVkUdoSa3TP9fwo=; b=hNinVss/IatGzdBlpBpEf3EeVzEO+AMrqEVDW9SE73t4Cymn7kLH9FpTwzLP74bMHWxgds 5xSI6RF9vzHkK2oAYjk6XstfSZbaaRFyKd/FBvUITCXRqLxWVftvg8RklGUUpjcEPT3MyH f1UPubkFHQ4VsqvFLlMPlJsscjJuMEB/RA6J1pEAoFMBJvUNPoAapFhmA4V9SX2LUiL+jw JHumRpciNyvYmC2ZTvDn116IWtL6qEmgZFPEKhv7gDWGwH0BiZq9gFZ/oJrWlua53eFHZm lPw/o/lu7Fm0bmBey7IbyRp0X655884tCmjhH/fVezYax3Bdpdkzj6JJjXhhRA== From: Rosalie Wanders DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/sbe5AapSrG6r3iBm0A/wH45Y9WOVkUdoSa3TP9fwo=; b=pQYYykm9uf3KQxA5YOiFsje8ASRK//ZEL9oFMJTRsPHkOnKqIYl+0QB+V9fkNYRol2H8RK G4iK6d/TOx0kieWfFxIYvTFzeR9jWaU7i2ewhzSEDpe2cJF36iX8CRI647wj6tOKwb52/I PnTJadLz89TVMmfNT/l8zxAPW2NFgP+ClaQSxCrEqIM7dPebVaU51RWNJozWtNgCalfSKT /S0/xtiYZcnPOzRJEW8eY1I4jtShIiSvhw+aH4ByCeVAY8p1Z+TkowwA0gxB1gk/XXZWdR 0Kpv36JOcfoP6dbBaS6Hz3VtFGpbV086NXefFZc+OxYqMIaXKlUeDrVkUxyAfA== To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rosalie Wanders Subject: [PATCH v2 2/4] HID: sony: use guard() and scoped_guard() Date: Tue, 16 Jun 2026 22:50:41 +0200 Message-ID: <20260616205042.6671-4-rosalie@mailbox.org> In-Reply-To: <20260616205042.6671-2-rosalie@mailbox.org> References: <20260616205042.6671-2-rosalie@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: g9h6z9b8rfrypyqk8udbe5gens3qzgw8 X-MBO-RS-ID: 397d8e5db9a326c155c Content-Type: text/plain; charset="utf-8" This replaces the spin_lock_irqsave() and spin_unlock_irqrestore() calls with the RAII guard() and scoped_guard(). Signed-off-by: Rosalie Wanders --- drivers/hid/hid-sony.c | 62 ++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 2d9a5261b63f..84df55c3cbe1 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -29,6 +29,7 @@ * There will be no PIN request from the device. */ =20 +#include #include #include #include @@ -571,14 +572,12 @@ static void sony_set_leds(struct sony_sc *sc); static inline void sony_schedule_work(struct sony_sc *sc, enum sony_worker which) { - unsigned long flags; - switch (which) { case SONY_WORKER_STATE: - spin_lock_irqsave(&sc->lock, flags); - if (!sc->defer_initialization && sc->state_worker_initialized) - schedule_work(&sc->state_worker); - spin_unlock_irqrestore(&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + if (!sc->defer_initialization && sc->state_worker_initialized) + schedule_work(&sc->state_worker); + } break; } } @@ -951,7 +950,6 @@ static const u8 *sony_report_fixup(struct hid_device *h= dev, u8 *rdesc, static int sixaxis_raw_event(struct sony_sc *sc, u8 *rd, int size) { static const u8 sixaxis_battery_capacity[] =3D { 0, 1, 25, 50, 75, 100 }; - unsigned long flags; int offset; u8 index; u8 battery_capacity; @@ -999,10 +997,10 @@ static int sixaxis_raw_event(struct sony_sc *sc, u8 *= rd, int size) battery_status =3D POWER_SUPPLY_STATUS_DISCHARGING; } =20 - spin_lock_irqsave(&sc->lock, flags); - sc->battery_capacity =3D battery_capacity; - sc->battery_status =3D battery_status; - spin_unlock_irqrestore(&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->battery_capacity =3D battery_capacity; + sc->battery_status =3D battery_status; + } =20 if (sc->quirks & SIXAXIS_CONTROLLER) { int val; @@ -1148,7 +1146,6 @@ static int rb4_ps5_guitar_raw_event(struct sony_sc *s= c, u8 *rd, int size) u8 battery_data; u8 battery_capacity; u8 battery_status; - unsigned long flags; =20 if (unlikely(size !=3D 64 || rd[0] !=3D 0x01)) return 0; @@ -1191,10 +1188,10 @@ static int rb4_ps5_guitar_raw_event(struct sony_sc = *sc, u8 *rd, int size) break; } =20 - spin_lock_irqsave(&sc->lock, flags); - sc->battery_capacity =3D battery_capacity; - sc->battery_status =3D battery_status; - spin_unlock_irqrestore(&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->battery_capacity =3D battery_capacity; + sc->battery_status =3D battery_status; + } =20 input_sync(sc->input_dev); return 0; @@ -1885,15 +1882,14 @@ static int sony_battery_get_property(struct power_s= upply *psy, union power_supply_propval *val) { struct sony_sc *sc =3D power_supply_get_drvdata(psy); - unsigned long flags; int ret =3D 0; u8 battery_capacity; int battery_status; =20 - spin_lock_irqsave(&sc->lock, flags); - battery_capacity =3D sc->battery_capacity; - battery_status =3D sc->battery_status; - spin_unlock_irqrestore(&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + battery_capacity =3D sc->battery_capacity; + battery_status =3D sc->battery_status; + } =20 switch (psp) { case POWER_SUPPLY_PROP_PRESENT: @@ -1975,10 +1971,9 @@ static inline int sony_compare_connection_type(struc= t sony_sc *sc0, static int sony_check_add_dev_list(struct sony_sc *sc) { struct sony_sc *entry; - unsigned long flags; int ret; =20 - spin_lock_irqsave(&sony_dev_list_lock, flags); + guard(spinlock_irqsave)(&sony_dev_list_lock); =20 list_for_each_entry(entry, &sony_device_list, list_node) { ret =3D memcmp(sc->mac_address, entry->mac_address, @@ -1992,26 +1987,23 @@ static int sony_check_add_dev_list(struct sony_sc *= sc) "controller with MAC address %pMR already connected\n", sc->mac_address); } - goto unlock; + goto out; } } =20 ret =3D 0; list_add(&(sc->list_node), &sony_device_list); =20 -unlock: - spin_unlock_irqrestore(&sony_dev_list_lock, flags); +out: return ret; } =20 static void sony_remove_dev_list(struct sony_sc *sc) { - unsigned long flags; - if (sc->list_node.next) { - spin_lock_irqsave(&sony_dev_list_lock, flags); - list_del(&(sc->list_node)); - spin_unlock_irqrestore(&sony_dev_list_lock, flags); + scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { + list_del(&(sc->list_node)); + } } } =20 @@ -2145,12 +2137,10 @@ static inline void sony_init_output_report(struct s= ony_sc *sc, =20 static inline void sony_cancel_work_sync(struct sony_sc *sc) { - unsigned long flags; - if (sc->state_worker_initialized) { - spin_lock_irqsave(&sc->lock, flags); - sc->state_worker_initialized =3D 0; - spin_unlock_irqrestore(&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->state_worker_initialized =3D 0; + } cancel_work_sync(&sc->state_worker); } } --=20 2.54.0 From nobody Fri Jun 19 22:18:44 2026 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5CDD39D6F6; Tue, 16 Jun 2026 20:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643089; cv=none; b=fp4sEUy8134AjWegmFxdKGvvHokm2a16Bt9lC1QbhTD11ectm2Am45nI4qzluPYrvGmlXBWXRoPWu/fOV8ba+pn723UBnLalpFIM4Wp/UWiLCl8Th3ZfWmHY1hNdTOxzNkmuyPn+98VsbJIZ74JyHdSK7xd4J5a/1urfo2WOECg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643089; c=relaxed/simple; bh=OQiQk5FKeVvhPZ1ZyAmGFF1PrRpfkCIJ0cxb9YtkaeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X6b0y0+HyslYHqergPY06q96C5ovIDVRHsU+lAS3DAUDw22VM3NsxzfnUwcNNXcd7wRZ/4ZzEV/S33hQXJkGNgqM7hI44/MiWbwCEwj8JWLzXVPLxqA7mFC+Wv00ry1hlPrWeZoPJbfN8JuU02MaEehqVzUipr/DfB76rVxFpB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=MIWJlpWn; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=OQNUiTc7; arc=none smtp.client-ip=80.241.56.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="MIWJlpWn"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="OQNUiTc7" Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4gfzfz5g1Cz9tN7; Tue, 16 Jun 2026 22:51:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XJG5z4yGA2fTT6p9RAokKoGIXdOZMaoZ/gCQfQ8Jr8I=; b=MIWJlpWnQlff/pLV7/cgyGDBl6T8790H6iHhUaSosm8rqgEevkIsDNHGVYWHHnLaddZC7N f4VsHNHyaf5EGcNOPk6vxolpdaUr46XuSTOJHkWi6dT7MAzbei7SlvK/Q//O4XXeROCGLq bv1HRgnsJ70Kpnxvc9eP9hlInrj9m2VoqaqFpXpsG/RpH5oAenTGYke8wv1fKncgXtef9g XDAIyl+5Fvz6PzUpZAFyY6xLjfqi5w34o7+RIrPXz5Z6KClyZ3WCFRRRF7mZISPAYTMdWI RSz0qFx6wSi3WJhjjScX5i1nl4usnU3sntxsf6WLTovjUWA2yooq39mecgiftg== From: Rosalie Wanders DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XJG5z4yGA2fTT6p9RAokKoGIXdOZMaoZ/gCQfQ8Jr8I=; b=OQNUiTc758CuURn7ymoDtA3RASS57krRUSG10oq1yxQtwVBbKKwP01AtSWaHdMgT2WIKbE aJE7tdGu0UV2y/5lB1PzsIu9H8yvpWSkaFIZw1GuVVcbCePj6UYu18593rXkUwYnc1vEW5 GxcrCa0myxCVvvrsB1qQmPjXyOymLvhOOknL+/dAxMq6A6ToDqBrmiN6MNkcb8cg6R0vMj /letjTcBCSmLm2LhPGpAx91arUiPgJXAPUtxegNfNYmfmqZundeNt16xRHTnlvMc1Aqdut Mex/iCbPL5VB1S7SqK0d+dd07L27K2iwnYmYxA+39zKIYQNsPKxqgvyhTDcGNg== To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rosalie Wanders Subject: [PATCH v2 3/4] HID: sony: remove unneeded which argument from sony_schedule_work() Date: Tue, 16 Jun 2026 22:50:42 +0200 Message-ID: <20260616205042.6671-5-rosalie@mailbox.org> In-Reply-To: <20260616205042.6671-2-rosalie@mailbox.org> References: <20260616205042.6671-2-rosalie@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-ID: a9638ce9cf04dbfa285 X-MBO-RS-META: dar4m95ghq3y97xs1s3ccn655txcz1rm Content-Type: text/plain; charset="utf-8" The sony_worker enum only had a single member, so removing it simplifies sony_schedule_work(). Signed-off-by: Rosalie Wanders --- drivers/hid/hid-sony.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 84df55c3cbe1..ff681ebc76ce 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -523,10 +523,6 @@ static DEFINE_SPINLOCK(sony_dev_list_lock); static LIST_HEAD(sony_device_list); static DEFINE_IDA(sony_device_id_allocator); =20 -enum sony_worker { - SONY_WORKER_STATE -}; - struct sony_sc { spinlock_t lock; struct list_head list_node; @@ -569,17 +565,11 @@ struct sony_sc { =20 static void sony_set_leds(struct sony_sc *sc); =20 -static inline void sony_schedule_work(struct sony_sc *sc, - enum sony_worker which) +static inline void sony_schedule_work(struct sony_sc *sc) { - switch (which) { - case SONY_WORKER_STATE: - scoped_guard(spinlock_irqsave, &sc->lock) { - if (!sc->defer_initialization && sc->state_worker_initialized) - schedule_work(&sc->state_worker); - } - break; - } + guard(spinlock_irqsave)(&sc->lock); + if (!sc->defer_initialization && sc->state_worker_initialized) + schedule_work(&sc->state_worker); } =20 static void ghl_magic_poke_cb(struct urb *urb) @@ -1211,7 +1201,7 @@ static int sony_raw_event(struct hid_device *hdev, st= ruct hid_report *report, =20 if (unlikely(sc->defer_initialization)) { sc->defer_initialization =3D 0; - sony_schedule_work(sc, SONY_WORKER_STATE); + sony_schedule_work(sc); } =20 return 0; @@ -1520,7 +1510,7 @@ static void buzz_set_leds(struct sony_sc *sc) static void sony_set_leds(struct sony_sc *sc) { if (!(sc->quirks & BUZZ_CONTROLLER)) - sony_schedule_work(sc, SONY_WORKER_STATE); + sony_schedule_work(sc); else buzz_set_leds(sc); } @@ -1631,7 +1621,7 @@ static int sony_led_blink_set(struct led_classdev *le= d, unsigned long *delay_on, new_off !=3D drv_data->led_delay_off[n]) { drv_data->led_delay_on[n] =3D new_on; drv_data->led_delay_off[n] =3D new_off; - sony_schedule_work(drv_data, SONY_WORKER_STATE); + sony_schedule_work(drv_data); } =20 return 0; @@ -1859,7 +1849,7 @@ static int sony_play_effect(struct input_dev *dev, vo= id *data, sc->left =3D effect->u.rumble.strong_magnitude / 256; sc->right =3D effect->u.rumble.weak_magnitude / 256; =20 - sony_schedule_work(sc, SONY_WORKER_STATE); + sony_schedule_work(sc); return 0; } =20 --=20 2.54.0 From nobody Fri Jun 19 22:18:44 2026 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D44323A59A7; Tue, 16 Jun 2026 20:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643095; cv=none; b=Eerqkvcx+Gc5WnH2dnILvHDwBdjj4H+nZ6wVeqvz0DPnc+LivfEwDy1k9X3Aj0wIzQj/EfuueE9dqUqOCDlX3OHjbcWgq+sd9sw6G83IFtEH3Qqwn3mZlZoyK0zNH8vXoWCQiTJJn4961AiX5n3le11CxyJrz50aueEKB3PMsjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781643095; c=relaxed/simple; bh=VFb2FxuhLCRMmPj4fC2L9d2sNR6IU0C1GuoKIlJQm6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=batAFQr/zmgbikplMiZJR6f9sEARPys5b3f9f4G7FDsda1eF4+cFxo6eOawx42MASShVqzVZGPDbfChBtUnBdTiEyMczcaTOyPMrCyexEYDG9KitUxObDKhV3ev371TonHXsoonakoH0SMIP6kd8x9mGuJCTiL2tV0ak5QzMEBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=n4wvlrPw; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=Z8WTLcY9; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="n4wvlrPw"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="Z8WTLcY9" Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4gfzg10BYlz9v1D; Tue, 16 Jun 2026 22:51:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hf6FTAk6TK1D0M6gzE98qOg22WFwdTvdp/dqs3D6Ev0=; b=n4wvlrPwJKBNuw41ShfPrQz1S4l0Qj7jmaKbEfGPX41Se6I1oHUrli38phhvTKw8vbgNU5 xaq04tIeze34U5sMJlBJTCTBmOr8PRhMlxrSyVfn4mdqF097LZn1TfmAUNKcqQqTi5uRoW YMKLGcpyLoSc9KwwSDrkfeO3hhV7EhNXD/IUReUo/eDkBun0Hsu4aZOLx/DrjSwGCEVxLM KGFAx2yyAGpxAhsB4joaGlBI8hpOP6mB7thkS6/+x6SBuqLqhQIPyAdMXM6UOE1/JIu/ch XCZoKVhC5mPEfSy9OToTcVgktwy0Uh0KUIhceWjDRpY5c655NpwfOzPtddm7SA== Authentication-Results: outgoing_mbo_mout; dkim=pass header.d=mailbox.org header.s=mail20150812 header.b=Z8WTLcY9; spf=pass (outgoing_mbo_mout: domain of rosalie@mailbox.org designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=rosalie@mailbox.org From: Rosalie Wanders DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1781643083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hf6FTAk6TK1D0M6gzE98qOg22WFwdTvdp/dqs3D6Ev0=; b=Z8WTLcY9+rH4OQe3GmoAlIvrww9OI+isK0bpvncXEepL1NzXH35sYLs7virL6oTgvFxJsQ +Kc4Gvzh5T434TeJM2s1UUi2/Jq/uko/VfxH+q4F48JxeDj1hVUZlIQuB1cGlC9dvk47oc Yy/MfQ0I6WYZH17BIT6TsbsHiLiycCAZAQjXwF3J4ja0AqYghl9sDvvf4P+ojV53CM4Tml EbSidEpwAVYUzjzMN61hPfstAU/7fZn8zCoHXjDFxIr49qBsyFs5193RXq0PIk3hpEiHs0 ttRfhBNNATXBxIEmHl4n/8Hfn4SbmExNsT0eNlncNC20UXB636NXkM8aEXuNjw== To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rosalie Wanders Subject: [PATCH v2 4/4] HID: sony: use devm_kasprintf() Date: Tue, 16 Jun 2026 22:50:43 +0200 Message-ID: <20260616205042.6671-6-rosalie@mailbox.org> In-Reply-To: <20260616205042.6671-2-rosalie@mailbox.org> References: <20260616205042.6671-2-rosalie@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: eejc86mgrhqr1e3tk3c96p77hh6o5r5n X-MBO-RS-ID: 70ba1e4fa4419c8c539 X-Rspamd-Queue-Id: 4gfzg10BYlz9v1D Content-Type: text/plain; charset="utf-8" Using devm_kasprintf() makes the code less error-prone. Signed-off-by: Rosalie Wanders --- drivers/hid/hid-sony.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index ff681ebc76ce..253fff4066eb 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1272,8 +1272,6 @@ static int sony_mapping(struct hid_device *hdev, stru= ct hid_input *hi, static int sony_register_touchpad(struct sony_sc *sc, int touch_count, int w, int h, int touch_major, int touch_minor, int orientation) { - size_t name_sz; - char *name; int ret; =20 sc->touchpad =3D devm_input_allocate_device(&sc->hdev->dev); @@ -1295,12 +1293,10 @@ static int sony_register_touchpad(struct sony_sc *s= c, int touch_count, * a suffix. Other devices which were added later like Sony TV remotes * inhirited this suffix. */ - name_sz =3D strlen(sc->hdev->name) + sizeof(TOUCHPAD_SUFFIX); - name =3D devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); - if (!name) + sc->touchpad->name =3D devm_kasprintf(&sc->hdev->dev, GFP_KERNEL, "%s" TO= UCHPAD_SUFFIX, + sc->hdev->name); + if (!sc->touchpad->name) return -ENOMEM; - snprintf(name, name_sz, "%s" TOUCHPAD_SUFFIX, sc->hdev->name); - sc->touchpad->name =3D name; =20 /* We map the button underneath the touchpad to BTN_LEFT. */ __set_bit(EV_KEY, sc->touchpad->evbit); @@ -1337,8 +1333,6 @@ static int sony_register_touchpad(struct sony_sc *sc,= int touch_count, =20 static int sony_register_sensors(struct sony_sc *sc) { - size_t name_sz; - char *name; int ret; =20 sc->sensor_dev =3D devm_input_allocate_device(&sc->hdev->dev); @@ -1357,12 +1351,10 @@ static int sony_register_sensors(struct sony_sc *sc) /* Append a suffix to the controller name as there are various * DS4 compatible non-Sony devices with different names. */ - name_sz =3D strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); - name =3D devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); - if (!name) + sc->sensor_dev->name =3D devm_kasprintf(&sc->hdev->dev, GFP_KERNEL, "%s" = SENSOR_SUFFIX, + sc->hdev->name); + if (!sc->sensor_dev->name) return -ENOMEM; - snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); - sc->sensor_dev->name =3D name; =20 if (sc->quirks & SIXAXIS_CONTROLLER) { /* For the DS3 we only support the accelerometer, which works --=20 2.54.0