From patchwork Wed Feb 7 16:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Staudt X-Patchwork-Id: 197981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2354565dyb; Wed, 7 Feb 2024 08:38:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4hgAaOwIZSYT6GkS584DGmR8vX3keYJWt79OPZYs60OFwiPbYt981WdIkSu7+B5yItEZ8 X-Received: by 2002:a9d:7ac5:0:b0:6e1:377e:c413 with SMTP id m5-20020a9d7ac5000000b006e1377ec413mr7085124otn.27.1707323905673; Wed, 07 Feb 2024 08:38:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707323905; cv=pass; d=google.com; s=arc-20160816; b=ulU8OXIRum55VueFesmC2PX/u4o7+YMqq9H4rqQaJfvHNCWBmsv6hK/u+7tz74UzJa UnynCTcZn2XYdJ7JtvNKevyk1WeZq7xZqeIxR1ylySe5HZYPIVkmRILLF2YamdqF4t/g TlzXhC7S4lYbWn86leynhs3L46IN/k5Gs99OCXG8NE2iztjUyaNZY4uWj8RVAmgtP3dE cv1jM8Jvn//sB3FiLFcw0VLbOCOuWg3wQUTGu/EPNX9av3yYXULB+zI+GuN3h0J90xI6 1mXIldKMyzwg5dO+r3zW29a8E3kbJG/lOZ+oxAWMvPjxS0DE3OnXa1yYB33dlEaGbQkY 3DUA== ARC-Message-Signature: i=2; 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=qxIeEi5peV0OLUuKYYF+dTjqsIYyD1FPg3/7V75r7uo=; fh=Ip5sdu2CDnn7gC6vIk7W5FkWkYHz558FphrleyKkkqw=; b=rxVljCQLIQv0atePzK0dBtfLU6mBS+PmIn7dJ6Dqg/M5MyUx4vqWfUAsd529hPy8Zp vWiUXKskt1/BSTNEHvn8JB3s03Zpc7Vf+ZP11uncjCtMv3rJdO52/DF6QTDYEOR9BY1S 5AEJG7A+v2ed51Gd3nnXF4vfkm4OYDbUutQ8U74cNkj2viPs/fp6lEBRue5v0PRAEkbH vaj7EENmcfRL4lTOtou2+pvGS3XkHjkBMGJRxp4NagbcQktAINHir0mYee0dL62eAHrS Gw7UBmaGw/BEZ4h4zVuslWaTpZjpuGehcdUMHuMN1KyuNQJrWIrI25E4TGilkOTl5M86 7MHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=enpas.org); spf=pass (google.com: domain of linux-kernel+bounces-56777-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56777-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWZ+eRoWHvijxj+N5+9V7wXSCkX8QpqqT4P66e9+vtNnJCPhgZxS7nvEQwPpTcArq6tppYriBNKyJwv7mrtZDz5yVG8MQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n4-20020a05622a11c400b0042c312be382si1442285qtk.539.2024.02.07.08.38.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:38:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56777-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=enpas.org); spf=pass (google.com: domain of linux-kernel+bounces-56777-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56777-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 69DFA1C21CC3 for ; Wed, 7 Feb 2024 16:38:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A3B982897; Wed, 7 Feb 2024 16:37:42 +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 5595033CA; Wed, 7 Feb 2024 16:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.38.239.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707323860; cv=none; b=NowLc3Y4tzVEpgtAQSBrsT4En2O4335C0r9FDHV0SwhsciZXElnI8L2YItR35Lao3RIsWy4eHLaZ8mpuc7SmaS0Dz3+31DOcBdT+GWvYdQkXiNTkj9KgpPe8F1lbVbOAS0fqa/bkpHUcyl1iXol+9+Is1zKYytsdk3UW6YyBmkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707323860; c=relaxed/simple; bh=vqtUsSo5ghicGhv7xGcTyQ2ci1iQwKusQkLqNXAcFzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sJDOYtwd/VghDpaals8pnlZZZy3oeZ5A60WmdRG1X7NrkAtcSbJ2hT8VTlX595Cx+OVdvv1OblU/6aScnp/vLIyPligyOZj3EQivCr6ablmKw1ejuy9R+egbSZpfXA34vlHnjDQqcAYu10gtjEfldVspPAM7VnkijrV5+NnChiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=enpas.org; spf=pass smtp.mailfrom=enpas.org; arc=none smtp.client-ip=46.38.239.100 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 5B9A4100BC4; Wed, 7 Feb 2024 16:37:34 +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 v2 3/5] HID: playstation: DS4: Don't fail on calibration data request Date: Thu, 8 Feb 2024 01:36:45 +0900 Message-Id: <20240207163647.15792-4-max@enpas.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240207163647.15792-1-max@enpas.org> References: <20240207163647.15792-1-max@enpas.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790258871894513545 X-GMAIL-MSGID: 1790258871894513545 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 | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index df50ca4dab90..53bfc2828a61 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 @@ -1796,26 +1798,27 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4) continue; } - hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret); + hid_warn(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) { - hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret); - goto err_free; - } + + if (ret) + hid_warn(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret); } + /* 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; } @@ -2568,8 +2574,8 @@ 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_warn(hdev, "Failed to get calibration data from DualShock4\n"); + hid_warn(hdev, "Gyroscope and accelerometer will be inaccurate.\n"); } ds4->gamepad = ps_gamepad_create(hdev, dualshock4_play_effect);