From patchwork Tue Feb 11 14:02:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 864393 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FF2224C698; Tue, 11 Feb 2025 14:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282586; cv=none; b=kVRyx5Y2xs5y2bz8YUUIlCsvyDZfi0i4MmTD2wdSHTzEErA50QARHofbbd2zzBWi+XhJjHGXSux1i04kEd2CXZfZkPwhXocOWanKX/T0Jz4jmnNIjmyIEDHLTTjrrpaubyD0Tu8ne04g7DxeYhnO4cbsqKQSK0Usbj3dqptT27U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282586; c=relaxed/simple; bh=eUbxUt5xpTtxEzNiYKqCsSF7kyQ0xB70W44K9/NfqI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WGwEN4X4Bj/xb+7aP+0m6cVOajCM1Fwd4Mud0UD5wbpSUDULVPKhGLdRswZfmGVOmUeltr7sKzm/3jZhjNEuLfFMFRP888SLb53LSWTW2ZmPDduxZ5A0sIAy/Z2OSWy7vsOadp0Gp/sikY/fQwP3hBLc9AH/8Fa6azGvphFOq7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=delR3+b1; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="delR3+b1" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5450e09b65fso250285e87.3; Tue, 11 Feb 2025 06:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739282583; x=1739887383; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KSNQINkXkN6zTTIn4J3zlyOnrY9qbrfu5RjfBEk7Udo=; b=delR3+b1DVqb5vs2ByU5cxrYZ11LsaB+uZNFfl5rbPNOiMDlz55CFOPXNaQVSmL37R j/ZZpza0RERYOzuJM/QGEa8z7c9BhBqWE+50uP6cBlKb600Rq1KhqSSdd+kQNPgOdUd/ zOsRoEtLvRQ+0w1/Slg9iaH0TFM0g5Kq5wrjbTP8M6FHQxcS939VM2bbacDQars3ReoA 0wmbo7b+Vkdwf2pCt8S7P4QpL97P4/7f/MwdU5Xl82lvUMt6Ez/oWRGrDKtJ2GP7AyXC P9e0JHjeZ8dHJDwGdYbbRh9Et9b7AeLdfUkt1yKwE8DASqtisq0euqRAnu9cgcg9dAF2 yL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739282583; x=1739887383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KSNQINkXkN6zTTIn4J3zlyOnrY9qbrfu5RjfBEk7Udo=; b=k0rG6J/r+/781yW6Rdp1Alvj1Py5SXuL44XLw3jP1C9ymKIqkGoqRxDgv7nroMcRBr 65kGer3mhtpbpLh6C88p0rSfvTMQvXG5zixpPSALgJ5RoOJcfb4r1dbKA7Qj5YqzwqUW HXyYyBP4j5BbI1J1UsXVfjoyiCtiBe0H5O7ZincYJP5blyCH/Oi6/E3euE9Kfsv8pniT OKwzCeqEteeb+eYB3tDAc5sdQJS+3gBWBqKo3PwlhYis7S9X2DPBi6xR5rq4muVzLebv XP/xIS9mUY6HBmBnFpp5glsFqeuMeH7XnZn0kgwCaxqbmYnpr6rFUWdes5NQYOfvElGT oftQ== X-Forwarded-Encrypted: i=1; AJvYcCWPPyG47pWKFuBst8cAX93ZkIHXismQuxDm828yH93EV8h84PGnvPzXWkJJ2St8+eemyNulIFWeFp67@vger.kernel.org, AJvYcCXpX5X2QzDkr4eF/tNwpRlvgJL0pWWN1MIZ5eOzT+a4Q8cOkWU41smgHDh+pv6Yph8kYjdfCLA5H+NxiQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwnOgLwhtBVL9HeYmFiY+14g9HBQiuStHDNUKWqfZGVxN/mcpQG RIaJe+mg2Ofe1cCzwsnfMaAhsGafjyZZPRH68dYeq/5fvTF6+Dh9 X-Gm-Gg: ASbGncu94RJy51uzUyih0PbbACc0eFvITlga91FPGxrmlSPL8pRcOh4XlBb+sMZbbHq hVBGoO4GwxqGhadyI6EiTif4buRAxOcza9Pg2RnEPEV/O09d/CigqkRdHzjhT7PVJ1Wp/+m4XLb new9SFKLiMfY5D9+H6Z5+RmwxJBjNt+ij3lxeTcJ6kzGu98nKhIahnDX6J+nw7L/LyH6EiT6bF9 S+2CguhAuzUATymZ1wIb3/2fAgtKCI/Fo2GukmQ/65DfvGrY5+poxCHCcrwJhCI7CZVEI226lai oFvT5i439sHZxCeyRnZ49KkAaA8jZkiT2cUc8fOH16j/7/jGSZ9D4TOHP8WA6w== X-Google-Smtp-Source: AGHT+IFMwKZtZNvbeY1OPx+TfviYiHqhlkhU9e99ji237Ci+JASpfPOndVu+FqBJhHKDkXMuYqbdaw== X-Received: by 2002:ac2:57c2:0:b0:545:fa6:3590 with SMTP id 2adb3069b0e04-54513ad2d75mr237245e87.1.1739282581958; Tue, 11 Feb 2025 06:03:01 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-545014af0d0sm1118721e87.184.2025.02.11.06.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2025 06:03:00 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 2/6] HID: pidff: Make sure to fetch pool before checking SIMULTANEOUS_MAX Date: Tue, 11 Feb 2025 15:02:48 +0100 Message-ID: <20250211140252.702104-3-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> References: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As noted by Anssi some 20 years ago, pool report is sometimes messed up. This worked fine on many devices but casued oops on VRS DirectForce PRO. Here, we're making sure pool report is refetched before trying to access any of it's fields. While loop was replaced with a for loop + exit conditions were moved aroud to decrease the possibility of creating an infinite loop scenario. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index f23381b6e344..503f643b59ca 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -604,28 +604,25 @@ static void pidff_reset(struct pidff_device *pidff) } /* - * Refetch pool report + * Fetch pool report */ static void pidff_fetch_pool(struct pidff_device *pidff) { - if (!pidff->pool[PID_SIMULTANEOUS_MAX].value) - return; + int i; + struct hid_device *hid = pidff->hid; - int i = 0; - while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) { - hid_dbg(pidff->hid, "pid_pool requested again\n"); - hid_hw_request(pidff->hid, pidff->reports[PID_POOL], - HID_REQ_GET_REPORT); - hid_hw_wait(pidff->hid); + /* Repeat if PID_SIMULTANEOUS_MAX < 2 to make sure it's correct */ + for(i = 0; i < 20; i++) { + hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT); + hid_hw_wait(hid); - /* break after 20 tries with SIMULTANEOUS_MAX < 2 */ - if (i++ > 20) { - hid_warn(pidff->hid, - "device reports %d simultaneous effects\n", - pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); - break; - } + if (!pidff->pool[PID_SIMULTANEOUS_MAX].value) + return; + if (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] >= 2) + return; } + hid_warn(hid, "device reports %d simultaneous effects\n", + pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); } /* From patchwork Tue Feb 11 14:02:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 864392 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BED3224CECB; Tue, 11 Feb 2025 14:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282589; cv=none; b=ohTc9OAeNtAjXdUMF8SJeO9wC+pN5S+gDFtRv700vBIVrV1zlvKo92XpL+eONsF+eqe+xnzAg9T9jU+uB+/r1eQbSebfw74juL0RUYwdBuJ3AobMFuj5snQ/yXErO4FF47Emzp/IDojOzXUJAdueBSWH1HxBT09v75MChnBnrok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282589; c=relaxed/simple; bh=M9WPL+4kweCWgWjygIKmUoc1um6eqqxRR5AeEaAqTc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YigWfi8tIDXUZ6oSzRgzG57yKNT+wi5TUQVIoXW+8mZaaQkmplya4YmI40M6/KXdnJledaXZRFHr4HgcuvPdOjG55CtwF7WY45prwZTDdHRE+q7170OF1qWNs1mn2cwQ8KwCQ8baVWAZkOFVkdIyHmoAWokGsRKP0nPd4MlKZRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UFELzzVa; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UFELzzVa" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-54500ad66a6so488731e87.2; Tue, 11 Feb 2025 06:03:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739282586; x=1739887386; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZKCqqk95xHc52Uxa1Lo1nVI5gf0jsVsMcqbVtjY5cOI=; b=UFELzzVaN3IOKhC76bFjvnz5NjASzWXNxe1O+b1ZsT5SzXXEXRNBVRyhHFiCdD+g8L 8OhyrR7sTB6wZ0kkujyR72m9eCRU/7hRO9WlrQkhBYgIu8+cthdDWkLvT0LxwfUSTjUe KaheZDV003fa26CJDXxeXz5rQFW8PIyUKWNFaTBSCGRT6hBqardgbzOXn6yJL6oniRDI PvzlaRNTOpQxoLgV1Dqrq08kvPbq2cDf+23G+Pwj4fStzId2PeoeiBqqnXgVfauuYged rKid/J2od0cU3ZwodiPIOzNvO7MSu8mAB32AO89rDSni1WNvPLDy9K9Y9OAG5gpMVeEQ 0Vdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739282586; x=1739887386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZKCqqk95xHc52Uxa1Lo1nVI5gf0jsVsMcqbVtjY5cOI=; b=jY7gNKSyAs9K/mcwzdut+++GQ37+jRbMz1cLhL5DO/9DuVJOMCI5mXO78pHSl72/f1 9h4wikja6P+v4WaR4phDugmIhDIMnFXlPm9UtNYB/7qCpBe4jZfGd4edQ62sDttMTbM5 b2uFq0CpZ5CyEdYGZZ4/Bz+mx0BNMbvfOi45zk0UpCJ4HpD9DZQkXbm+9sT/WYEu9Nsi Y//6wIdpEeS5iv/SWHx3g9Ze3VsbKmqcaqcH6NW0XBCS76L9SUFJOjz+tYy+WkEcybUj 2ZZUOPpG31vDrUo2x2KKLT3/QM3unE54Adm/P0UDQel7hmg/+UDIJ18L/I0FPtkmpmCp +jkA== X-Forwarded-Encrypted: i=1; AJvYcCUyD9Bv2AUGofo9w9nVvGtFyxBApMvwzbgGI3lnK39bDeRnxrnEPjEVrVFuNB59xQCLsKf0JaRiefldqQ==@vger.kernel.org, AJvYcCX2uyK2QSl/Ca0luKYsnYY8QLQaCUU6DbH+kL5l88BZnJ0fGBSDC17FdpOe/+hfcGJe4zF8V0ZF6YFK@vger.kernel.org X-Gm-Message-State: AOJu0YyOxqyWrH1v7c9wTuSiqCICa3qpOfzVvuJVjCreUsT7/25WvFTX Jqp9kEPgLpIAX5zcVG1MQPM7m+NqN4ybDsgXiR6IMXYjeAihAET7wp+FdehT X-Gm-Gg: ASbGncuE6Lw0BT9TAvmsEDHOUcykol3blVExgy+0fNXm5drClISgOd0x4i6cASsrw6y m6Ap0tHtnPXBlBD68jW3xHyxHseOqU+bbahlYLLDZ2IVaK39krecjof411PgaXB9nioz49WB37G e/AgTFvNtBR6WtdbLkPW9ER5Uu5PMUS8rOfdZI/WodS6sJ72taZlmfx9tgonnadOHlBPM+KjZtA iJWRJ8GILCMlRqOD0XWr2o4T3o5KnYPrnpzL0QqBv4VUER0yKj8fior7xn7/dEprMIJ3ELf9Kac XZGsg49MhpJpPmd5yn7M/WfUTyYpnewCned4isqSHzbM9s/bkRG87QGnWW8Qrw== X-Google-Smtp-Source: AGHT+IHdCwDL85Br2dEHipAgPQz8thvJhxpwPHgl80tQ7iQPP0je9N++sloiHPJq15WQGfczfpVEAw== X-Received: by 2002:a05:6512:344a:b0:545:d54:2eb4 with SMTP id 2adb3069b0e04-54513b38d26mr238140e87.8.1739282585589; Tue, 11 Feb 2025 06:03:05 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-545014af0d0sm1118721e87.184.2025.02.11.06.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2025 06:03:04 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 4/6] HID: pidff: Comment and code style update Date: Tue, 11 Feb 2025 15:02:50 +0100 Message-ID: <20250211140252.702104-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> References: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update comments to fully conform to the Linux comment styling. Define Linux infinite effect duration (0) as FF_INFINITE Chanage Oleg's name order Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 57 +++++++++++++++------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index 503f643b59ca..e2508a4d754d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -3,13 +3,9 @@ * Force feedback driver for USB HID PID compliant devices * * Copyright (c) 2005, 2006 Anssi Hannula + * Upgraded 2025 by Oleg Makarenko and Tomasz Pakuła */ -/* - */ - -/* #define DEBUG */ - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include "hid-pidff.h" @@ -25,9 +21,9 @@ /* Linux Force Feedback API uses miliseconds as time unit */ #define FF_TIME_EXPONENT -3 +#define FF_INFINITE 0 /* Report usage table used to put reports into an array */ - #define PID_SET_EFFECT 0 #define PID_EFFECT_OPERATION 1 #define PID_DEVICE_GAIN 2 @@ -48,12 +44,12 @@ static const u8 pidff_reports[] = { 0x21, 0x77, 0x7d, 0x7f, 0x89, 0x90, 0x96, 0xab, 0x5a, 0x5f, 0x6e, 0x73, 0x74 }; - -/* device_control is really 0x95, but 0x96 specified as it is the usage of -the only field in that report */ +/* + * device_control is really 0x95, but 0x96 specified + * as it is the usage of the only field in that report. + */ /* PID special fields */ - #define PID_EFFECT_TYPE 0x25 #define PID_DIRECTION 0x57 #define PID_EFFECT_OPERATION_ARRAY 0x78 @@ -61,7 +57,6 @@ the only field in that report */ #define PID_DEVICE_CONTROL_ARRAY 0x96 /* Value usage tables used to put fields and values into arrays */ - #define PID_EFFECT_BLOCK_INDEX 0 #define PID_DURATION 1 @@ -119,7 +114,6 @@ static const u8 pidff_device_gain[] = { 0x7e }; static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; /* Special field key tables used to put special field keys into arrays */ - #define PID_ENABLE_ACTUATORS 0 #define PID_DISABLE_ACTUATORS 1 #define PID_STOP_ALL_EFFECTS 2 @@ -176,8 +170,10 @@ struct pidff_device { struct pidff_usage effect_operation[sizeof(pidff_effect_operation)]; struct pidff_usage block_free[sizeof(pidff_block_free)]; - /* Special field is a field that is not composed of - usage<->value pairs that pidff_usage values are */ + /* + * Special field is a field that is not composed of + * usage<->value pairs that pidff_usage values are + */ /* Special field in create_new_effect */ struct hid_field *create_new_effect_type; @@ -222,7 +218,7 @@ static s32 pidff_clamp(s32 i, struct hid_field *field) static int pidff_rescale(int i, int max, struct hid_field *field) { return i * (field->logical_maximum - field->logical_minimum) / max + - field->logical_minimum; + field->logical_minimum; } /* @@ -282,9 +278,8 @@ static void pidff_set_time(struct pidff_usage *usage, u16 time) static void pidff_set_duration(struct pidff_usage *usage, u16 duration) { - /* Convert infinite length from Linux API (0) - to PID standard (NULL) if needed */ - if (duration == 0) + /* Infinite value conversion from Linux API -> PID */ + if (duration == FF_INFINITE) duration = PID_INFINITE; if (duration == PID_INFINITE) { @@ -302,16 +297,16 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, struct ff_envelope *envelope) { pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] = - pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; + pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; pidff->set_envelope[PID_ATTACK_LEVEL].value[0] = - pidff_rescale(envelope->attack_level > - S16_MAX ? S16_MAX : envelope->attack_level, S16_MAX, - pidff->set_envelope[PID_ATTACK_LEVEL].field); + pidff_rescale(envelope->attack_level > + S16_MAX ? S16_MAX : envelope->attack_level, S16_MAX, + pidff->set_envelope[PID_ATTACK_LEVEL].field); pidff->set_envelope[PID_FADE_LEVEL].value[0] = - pidff_rescale(envelope->fade_level > - S16_MAX ? S16_MAX : envelope->fade_level, S16_MAX, - pidff->set_envelope[PID_FADE_LEVEL].field); + pidff_rescale(envelope->fade_level > + S16_MAX ? S16_MAX : envelope->fade_level, S16_MAX, + pidff->set_envelope[PID_FADE_LEVEL].field); pidff_set_time(&pidff->set_envelope[PID_ATTACK_TIME], envelope->attack_length); @@ -702,9 +697,7 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n) static int pidff_playback(struct input_dev *dev, int effect_id, int value) { struct pidff_device *pidff = dev->ff->private; - pidff_playback_pid(pidff, pidff->pid_id[effect_id], value); - return 0; } @@ -732,8 +725,11 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id) hid_dbg(pidff->hid, "starting to erase %d/%d\n", effect_id, pidff->pid_id[effect_id]); - /* Wait for the queue to clear. We do not want a full fifo to - prevent the effect removal. */ + + /* + * Wait for the queue to clear. We do not want + * a full fifo to prevent the effect removal. + */ hid_hw_wait(pidff->hid); pidff_playback_pid(pidff, pid_id, 0); pidff_erase_pid(pidff, pid_id); @@ -1239,7 +1235,6 @@ static int pidff_find_effects(struct pidff_device *pidff, set_bit(FF_FRICTION, dev->ffbit); return 0; - } #define PIDFF_FIND_FIELDS(name, report, strict) \ @@ -1370,12 +1365,10 @@ static int pidff_check_autocenter(struct pidff_device *pidff, hid_notice(pidff->hid, "device has unknown autocenter control method\n"); } - pidff_erase_pid(pidff, pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]); return 0; - } /* From patchwork Tue Feb 11 14:02:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Paku=C5=82a?= X-Patchwork-Id: 864391 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD78924CEC3; Tue, 11 Feb 2025 14:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282592; cv=none; b=Biy7svdKMEMgeAkrfEM319Yk3+NkuokgCspvhhIbSSZzxuOcFudTLPyhKenqEI+AyNYDUx75lanp1YgbMP6abemyy5rQ9sC84mUSY4eoD9qqNKqHRxLtnEoJjMUxbaHbcpcTjRLh8d18jP7zJ4ajacS5FUMbxZRausGDDq4cVis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739282592; c=relaxed/simple; bh=kNGRVi3mkE4Ik7DuVSzb0dE3caW/bhvIv27XtZ4uEmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jugcu3bzAOENGS2AIxSWA0PUuEOXa7wkf5t329kVd5ABi5l6j0gV19rQKR8tkFKzO/KR7B3dsRsLv4BbmMNsGZ7IFuaTrCk6nNIZJiHTzFNWPoWRfcMmJQ0oDvE5zD/4d/6G/anA5NgZIyyt2rJUzjWp23Pnhk4KBYOoDlP1xAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kP4DFTwa; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kP4DFTwa" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5450e08f300so283387e87.0; Tue, 11 Feb 2025 06:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739282589; x=1739887389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w2CWaXsm/K/mNvLz1mhLGG+mDBgTiXMcIaNXAmCgOmw=; b=kP4DFTwaG6UktNTEHN1ylbocF4K8KRWmONtKoM9fp+T7Sht9ZDElW/qGwYlqljNei5 eosxH/Ouq4djLJ3c4YAsDvqFnRpVBXcRSsy3tQRG1N5KHkAhF/VSbMHG7M4ko0DsJoJ3 Dy/Q4biFr5ii+7lgxBA9IAiXFDHxYJMHXL63+Yji7JFE9FySvcG7fIMLxx9cppbr/92c xh9CGbLtIhmDeTX9PBh9rahVP8oXiV1PVjI2/EQtQFKRS85P1cEmw2tIJ/fcyhEa0EtW rALqyjeiLcEXERRjU6Vg1z/0aVJz/8fZG/0IUYZ5K7DEl/e7zzqGtYmnxakW+SL1Nijw hCdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739282589; x=1739887389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w2CWaXsm/K/mNvLz1mhLGG+mDBgTiXMcIaNXAmCgOmw=; b=c6bTtJhsIlKOonQx/v7g4YMvco1gEFpKtu2GOMWBVT94nN0JNWDcDO/sxS8rV8qp3y wpjju9HLY44zcFP9FRi9tHH0czIm8n6UvrgtLEoYIi9c0J6vf4qoB9CUh+iAZC63UpNp Ah/n/pnZotzdU2nc786/1kI+G2BQNmM6IFfys2DO9JpSLNuwBr8knZru9uwrIE6FXNgm 68Ccmi2S/7AbKpihL6HDX+ZGTzQYmhRa9kQSUqi6bLY8/6SG8Ow9I82aBJoClp74uTzI swwG7TFzGvOVGC1dqNHIqYc3yriuIn7VaiDKfWfzsh9O6nHNkMnDIHO9ANfOCOdRvOU2 lgqA== X-Forwarded-Encrypted: i=1; AJvYcCVTM+DMDptXguuGQQO2sbVk3xIomSZzmytlgEiHwz8LM+o/P2v43WvnfqUpk8ZxgzlwfHp2Y32tdaZM@vger.kernel.org, AJvYcCXgX/vNIs0xjzexyNErEDL5/29si2gdLh4qDZe5+EqqekP0Nwal0vZdhhWSx7VaMCtu9ZHaBBJ0e4InRw==@vger.kernel.org X-Gm-Message-State: AOJu0YxTSl5JVsh5u/CWjkJ7Lgb0mOcdMlYQkaPk4i880yzkowl7XOGr 75VlPdDbSkRSkJLGLEWqUEzdFayPuNqHvZsqN7ajewhD35dkgPOl X-Gm-Gg: ASbGncs5USk7aQXXTv1YHlozfpiwqGhLRAZ/AwLnD+be5lQIH6ynIctTOjbDVULiKyu WE53i+nRWA3n3lA+bQHVKA0EmXgtk1SXCQYjD4C5NFyiTXW8G3Q1mCDrptWF5OSQCW8jihNlN/2 krwbW9ca4d0UrruPAnPyXvNUBHJdR7bjOEmTydh/D053mRrzsQCdrJGRLyTFXQRf93xAhG7nOG6 wdgjw3XsYDvjy02D0OLk20oOb0PIGvK5JnqxF/ocASjwl229xg22zEd96sS5AXDPXdvMF6vc70x EEF2vhGEi7bOH/Si/1/xb5Jb4vP+a5xQNAL7dwYhGYZnArpd0KNVYUFvqFrVHA== X-Google-Smtp-Source: AGHT+IHVPqTnF/S9xuKkuuUBxGGreITBRohMmM0gNs1PnjpP+f5eajnP/XaxJNiaIPpKHi4xf84zRg== X-Received: by 2002:a05:6512:b22:b0:545:ece:82d5 with SMTP id 2adb3069b0e04-5450ece849dmr827307e87.13.1739282587061; Tue, 11 Feb 2025 06:03:07 -0800 (PST) Received: from laptok.lan (89-64-31-140.dynamic.chello.pl. [89.64.31.140]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-545014af0d0sm1118721e87.184.2025.02.11.06.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2025 06:03:06 -0800 (PST) From: =?utf-8?q?Tomasz_Paku=C5=82a?= To: jikos@kernel.org, bentiss@kernel.org Cc: anssi.hannula@gmail.com, oleg@makarenk.ooo, linux-input@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 5/6] HID: pidff: Support device error response from PID_BLOCK_LOAD Date: Tue, 11 Feb 2025 15:02:51 +0100 Message-ID: <20250211140252.702104-6-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> References: <20250211140252.702104-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If an error happens on the device, the driver will no longer fall into the trap of reading this status 60 times before it decides that this reply won't change to success/memory full. Greatly reduces communication overhead during device error situation. Signed-off-by: Tomasz Pakuła --- drivers/hid/usbhid/hid-pidff.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index e2508a4d754d..d5734cbf745d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -138,7 +138,8 @@ static const u8 pidff_effect_types[] = { #define PID_BLOCK_LOAD_SUCCESS 0 #define PID_BLOCK_LOAD_FULL 1 -static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; +#define PID_BLOCK_LOAD_ERROR 2 +static const u8 pidff_block_load_status[] = { 0x8c, 0x8d, 0x8e}; #define PID_EFFECT_START 0 #define PID_EFFECT_STOP 1 @@ -666,6 +667,11 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); return -ENOSPC; } + if (pidff->block_load_status->value[0] == + pidff->status_id[PID_BLOCK_LOAD_ERROR]) { + hid_dbg(pidff->hid, "device error during effect creation\n"); + return -EREMOTEIO; + } } hid_err(pidff->hid, "pid_block_load failed 60 times\n"); return -EIO;