mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sanjay Govind <sanjay.govind9@gmail.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Rosalie Wanders <rosalie@mailbox.org>,
	Sanjay Govind <sanjay.govind9@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 2/2] HID: sony: fix battery name clash between RB4 PS5 guitars
Date: Tue,  1 Dec 2026 15:07:05 +1300	[thread overview]
Message-ID: <20261201020704.3545243-4-sanjay.govind9@gmail.com> (raw)
In-Reply-To: <20261201020704.3545243-2-sanjay.govind9@gmail.com>

Rock Band 4 PS5 guitars register a power supply named after their MAC
address, but the driver never reads a MAC address for them, so every
such guitar registers "sony_controller_battery_00:00:00:00:00:00".

With two of these guitars connected, registering the battery of the
second one fails, and as a battery registration failure aborts
sony_input_configured(), the second guitar is not usable at all:

  sysfs: cannot create duplicate filename '/class/power_supply/sony_controller_battery_00:00:00:00:00:00'
  ...
  sony 0003:3958:5600.0222: Unable to register battery device
  sony 0003:3958:5600.0222: failed to claim input

Allocate a device ID for these guitars, and append it to the battery
name when the MAC address is unknown.

Fixes: e4bdeaef0351 ("HID: sony: add battery status support for Rock Band 4 PS5 guitars")
Cc: stable@vger.kernel.org
Signed-off-by: Sanjay Govind <sanjay.govind9@gmail.com>
---

Notes:
    Tested with a Gibson SG (3651:8600) and a Gibson Kramer (3958:5600),
    both in PS5 mode over USB and connected at the same time. Without this
    patch, the guitar connected second fails to register its battery, with
    the sysfs warning above, and has no input device. With it, both guitars
    are usable and their batteries are registered as
    sony_controller_battery_00:00:00:00:00:00_0 and _1.
    
    Built hid-sony.ko with W=1 against the 7.3.6 headers, no warnings;
    checkpatch clean.
    
    The patch and changelog were written with the help of an AI coding
    assistant (Claude Opus 5.5).

 drivers/hid/hid-sony.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 7a25f5acce88..1f1152575ae4 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -31,6 +31,7 @@
 
 #include <linux/cleanup.h>
 #include <linux/device.h>
+#include <linux/etherdevice.h>
 #include <linux/hid.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -1906,13 +1907,21 @@ static int sony_battery_get_property(struct power_supply *psy,
 
 static int sony_battery_probe(struct sony_sc *sc, int append_dev_id)
 {
-	const char *battery_str_fmt = append_dev_id ?
-		"sony_controller_battery_%pMR_%i" :
-		"sony_controller_battery_%pMR";
 	struct power_supply_config psy_cfg = { .drv_data = sc, };
 	struct hid_device *hdev = sc->hdev;
+	const char *battery_str_fmt;
 	int ret;
 
+	/*
+	 * Devices without a MAC address, such as Rock Band 4 PS5 guitars,
+	 * would all get the same name, so use the device ID to tell them
+	 * apart.
+	 */
+	if (append_dev_id || is_zero_ether_addr(sc->mac_address))
+		battery_str_fmt = "sony_controller_battery_%pMR_%i";
+	else
+		battery_str_fmt = "sony_controller_battery_%pMR";
+
 	/*
 	 * Set the default battery level to 100% to avoid low battery warnings
 	 * if the battery is polled before the first device report is received.
@@ -2085,10 +2094,10 @@ static int sony_set_device_id(struct sony_sc *sc)
 	int ret;
 
 	/*
-	 * Only Sixaxis controllers get an id.
-	 * All others are set to -1.
+	 * Only Sixaxis controllers, and Rock Band 4 PS5 guitars which need it
+	 * to name their battery, get an id. All others are set to -1.
 	 */
-	if (sc->quirks & SIXAXIS_CONTROLLER) {
+	if (sc->quirks & (SIXAXIS_CONTROLLER | RB4_GUITAR_PS5)) {
 		ret = ida_alloc(&sony_device_id_allocator, GFP_KERNEL);
 		if (ret < 0) {
 			sc->device_id = -1;
-- 
2.56.1


      parent reply	other threads:[~2026-12-01  2:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  2:07 [PATCH 0/2] HID: sony: fix RB4 PS5 guitar battery handling Sanjay Govind
2026-12-01  2:07 ` [PATCH 1/2] HID: sony: handle RB4 PS5 guitars that do not report a battery level Sanjay Govind
2026-12-01  2:07 ` Sanjay Govind [this message]

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=20261201020704.3545243-4-sanjay.govind9@gmail.com \
    --to=sanjay.govind9@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rosalie@mailbox.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®