Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp576805rdb; Mon, 15 Jan 2024 06:51:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiVwPjifnc1lsY+ATpbaLZalQxtViKP7HvPhBlkwPbAGOQGvx6gcQaSSViZ23fIihJ1bz6 X-Received: by 2002:a05:6a21:32a3:b0:19a:2fcf:c48a with SMTP id yt35-20020a056a2132a300b0019a2fcfc48amr5991004pzb.5.1705330317188; Mon, 15 Jan 2024 06:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330317; cv=none; d=google.com; s=arc-20160816; b=StOIX9QNGbMdT67G1/Kx3GIQ0U1EoqCEqgQiflyAkXF/O3+wr5l696YAwrPkK6nNik J7RxVFXqfhJ7sjK6C+m7Qm0hzPaHzSjyD6f4C/oSz06Zy3ozyxAoS/qvKQ7VNsSG6cL5 GbsMSgdKiyRyslfPg/084IsFW6W4Nidzcwp0QkEBmiwrOZtO4NJ0jGpAzyXjpGPTbQGf l/jiHD6205dfD0uq9XeD4mtPa8vkIMJpuV8UNymKH9jJNvU7re2ltVB8Im3KuWl44hGX JbSixttxH+keNhcUybT4nOwbz1b4Mq9f9RemrlzkzLhLcNSNhY+XvMpfX4n1aIfB1GSX tt3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=uGyy5CQ+VTSM0sTxfsYr6J65ISsTQsrzlVu+E02BlCk=; fh=3M1PHg4byxu2MygWip944LqLZSq0Urk5Qa4iYXrexb8=; b=vSXG3vV/KWN96IaU9oZ6ClFCc/+YSM3ggNpwHKYseQkSf5MYjRmcKr4ZT7nkJMrFmR IYVkXo+e6zZEQ6A0oqsC+w3WRcoY0iinSTixXJamJG1wLGqXdr3daTPoKyfAxtT83XvT VWd72y67fF6avB+8jItv1FZVqigIGdiEzDfqHKTdG+g6/gkB1azvl+8nfUTqPwmfnRJT AH6jqUo+x64KqK1N2WwUIJrj6I8dkAmBz4keNoBs9MLlkK42ujP3neZGFYCufmlCh8oI wlSozxvIDSAvG0OggFrjLgYcnlrmSb/vUh3kaYri+JeYjBzVCPmXerHt/NgjbHiui3CS JBCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26139-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a28-20020a056a001d1c00b006d9fac3a70fsi9293737pfx.370.2024.01.15.06.51.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:51:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26139-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BAE7F282961 for ; Mon, 15 Jan 2024 14:51:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 006BD17BAF; Mon, 15 Jan 2024 14:48:59 +0000 (UTC) Received: from mail.enpas.org (zhong.enpas.org [46.38.239.100]) (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 8BFF7175B2; Mon, 15 Jan 2024 14:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=enpas.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=enpas.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail.enpas.org (Postfix) with ESMTPSA id 7859A10164D; Mon, 15 Jan 2024 14:48:52 +0000 (UTC) From: Max Staudt To: Roderick Colenbrander , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, max@enpas.org Subject: [PATCH v1 4/7] HID: playstation: DS4: Don't fail on calibration data request Date: Mon, 15 Jan 2024 23:45:35 +0900 Message-Id: <20240115144538.12018-5-max@enpas.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115144538.12018-1-max@enpas.org> References: <20240115144538.12018-1-max@enpas.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some third-party controllers can't report calibration data for the gyro/accelerometer. We can still use the gamepad as-is, so let's do that. Signed-off-by: Max Staudt --- drivers/hid/hid-playstation.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 12321cae4416..2bf44bd3cc8a 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1778,8 +1778,10 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4) int retries; buf = kzalloc(DS4_FEATURE_REPORT_CALIBRATION_SIZE, GFP_KERNEL); - if (!buf) - return -ENOMEM; + if (!buf) { + ret = -ENOMEM; + goto no_buffer_tail_check; + } /* We should normally receive the feature report data we asked * for, but hidraw applications such as Steam can issue feature @@ -1798,24 +1800,25 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4) hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret); ret = -EILSEQ; - goto err_free; } else { break; } } } else { /* Bluetooth */ buf = kzalloc(DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE, GFP_KERNEL); - if (!buf) - return -ENOMEM; + if (!buf) { + ret = -ENOMEM; + goto no_buffer_tail_check; + } ret = ps_get_report(hdev, DS4_FEATURE_REPORT_CALIBRATION_BT, buf, DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE, true); - if (ret) { + + if (ret) hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret); - goto err_free; - } } + /* Parse buffer. If the transfer failed, this safely copies zeroes. */ gyro_pitch_bias = get_unaligned_le16(&buf[1]); gyro_yaw_bias = get_unaligned_le16(&buf[3]); gyro_roll_bias = get_unaligned_le16(&buf[5]); @@ -1867,6 +1870,11 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4) ds4->gyro_calib_data[2].sens_denom = abs(gyro_roll_plus - gyro_roll_bias) + abs(gyro_roll_minus - gyro_roll_bias); + /* Done parsing the buffer, so let's free it. */ + kfree(buf); + +no_buffer_tail_check: + /* * Sanity check gyro calibration data. This is needed to prevent crashes * during report handling of virtual, clone or broken devices not implementing @@ -1919,8 +1927,6 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4) } } -err_free: - kfree(buf); return ret; } @@ -2571,7 +2577,7 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev) ret = dualshock4_get_calibration_data(ds4); if (ret) { hid_err(hdev, "Failed to get calibration data from DualShock4\n"); - goto err; + hid_err(hdev, "Gyroscope and accelerometer will be inaccurate.\n"); } ds4->gamepad = ps_gamepad_create(hdev, dualshock4_play_effect); -- 2.39.2