From nobody Sun Feb 8 14:10:40 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 8B5A22494FE for ; Mon, 29 Dec 2025 03:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766978281; cv=none; b=XDtsBpuGHMyPXgFScAmU4QerzNsp+Bg0byE1CnyuDrl9agsC6DGweDzbTSmpzXXLgFehMnjKARd+FHboan9fL56fSfT91Iuzi24pHgoIP1fQdTq0fKpp479mNqtMHOCfqepWPAde4TjpAIukKtyItUe2A81rRHgc+7/DWFprb70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766978281; c=relaxed/simple; bh=JYwujQFMXSGgCntgSP08tb0z8gWWluEo30iDiljW/dU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a4xDt5k9Va/ldE9f/H5GhSZM7eY68emHNnrAVEMRM8Ok1O4nzDlxWYZq6BDHwCTUnna5R5MsGB5fKUmOvaLeTLfQlZlehUs65GGSuOv54AD+nVIOdOnOXL1Wnw0q4eRxE3l/blKkh3ZMi3lbORJ4XfwDsG6WGT8xY6L2tktujjc= 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=m8pYdAwB; arc=none smtp.client-ip=209.85.214.179 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="m8pYdAwB" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-29efd139227so114971715ad.1 for ; Sun, 28 Dec 2025 19:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766978279; x=1767583079; 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=Jny3euFMoUvIIQc8PkVqUx2UEsum5WbafcB5Jo0OEm4=; b=m8pYdAwBYj/E9TBk4zT2/LZH91X5e1BrntbTrXBOvaCVHyxs8BigWfzTi2YnYcdFtq gva4Vor3jVOke0CogBm8eVgTcjKyJH1Edak+QNeSzfoHJiXPJDRINUcz+6MJ3eAqbOcI /F58yort6NG/RzofxcOCyjJjoDRFSqWI8W9yPrkk22drhTDKIHubCr4QxHAemif4o7oE 5Tfn2EU+wae2g7fKcj0QIHjAuGmk2DfiiODQyy3lleb6SFRLq/p75B7uInZa3+9pctfQ QbFTJtNnkl8Jr1kSiQp09hme0ce0ebDxry6PPlRPn5YoHntj02aoJjR8TDxLeOnVY6Q3 DcKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766978279; x=1767583079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Jny3euFMoUvIIQc8PkVqUx2UEsum5WbafcB5Jo0OEm4=; b=dzNdXVsYkI4Ptf7l85DjuOm1kBzWQQ0eXz8eliG0ePcZA0eCQKDYguceE600FaHBhl 1GR5nTWH7nTyJT4aZbOHLwObzcRSg7+Jer9fMRYxQMYjihWdfNrtHYZD3WW+8SfFP8L0 80n7IukFuDpjk5cXsQIK6/M4kMQbRytg5YtnUSODZHCHS3Mp3fZnTJ+CPJFDgCKPACp/ WwjxbqEZVSTZ0VdlHID0vdU8Bo4R8m5skztyPMyePD76Jj0z/Ai98tR/bJYcMa2AmB4K IaTraCn6FWcVMG3vlAKLs33LS5GTgwKuS5iMLYR9CXli8eOMTqhZzduW3wKeAUXQ6Ls+ BrLw== X-Forwarded-Encrypted: i=1; AJvYcCVa24V3qmcbvgh1S/v49mTKWKFMIepFg2J3BppU0Oby4Sxj9VypJIeqwDiEVJwOANFxDwjwnC2LBhxCIVc=@vger.kernel.org X-Gm-Message-State: AOJu0YxSHpplOuJkQkEqbtJ8nQK3nPkQDnmcsweRgepZhOB95WzC2S8L Vkvj1miCXQ7xWmQqCfyLwrQU5GC3kFlFWAQg47J1L9NLCJAaXMUGN6hj X-Gm-Gg: AY/fxX6mgxKTByjuEjAP7x1oJ1k5a3vZ/jA+lAUF0XF3JDha5YDUeZhCEfIu8IyWY40 jK0oGKL3+psHNfA56HQUsWDya72dbJPx1rrV6DEi1sbbLmaPuyrgHQSX1I6sKTGAEvJu0WIxTEi VS8dlYUFri8ygsPiXeL4rrSHOMH1rkR2E2rA98Bg2Q/3OOXC2AkC26CjTIo9JjYCZJ21Cujpvdg ZrHWb9r0UaKpC4YAdLyIPnKX1g5LbudSVTCw7QBE4dQ1sjFswoqHIcf4lYqKTxI+SJ4gPy6Npq2 OVmuVVXNDXCU0V5zfdm7hZ5lPg9NgSEdubxltzNXqNfiC2CMlyc555yXOtSbuoJehFfK4+E/UqR eu9xyhq7oqEq0zt54+l/MYoy9dTUynejUGNFjTzrRoVOswd4RuefY1fGVp0Z2WkjYrAgaoXObaY tW1AyLGrMWRxeqeMJH5OBm54GVhECH5WLVHhbapbMTA4hDfa1bNwGlT9u5YiFUNfw= X-Google-Smtp-Source: AGHT+IEpEdjauXjggn5SR7U1Q+y64OlZqNg4Yg894GTeht+XbUtbyA5M9bniZWJzFw9VSOjbvaSz6g== X-Received: by 2002:a05:7022:6199:b0:11f:1e59:4c2d with SMTP id a92af1059eb24-121721acb6dmr26336934c88.7.1766978278720; Sun, 28 Dec 2025 19:17:58 -0800 (PST) Received: from lappy (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121724dd7f5sm112992785c88.5.2025.12.28.19.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Dec 2025 19:17:58 -0800 (PST) From: "Derek J. Clark" To: Jiri Kosina , Benjamin Tissoires Cc: Mario Limonciello , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Derek J . Clark" , linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/16] include: device.h: Add named device attributes Date: Mon, 29 Dec 2025 03:17:38 +0000 Message-ID: <20251229031753.581664-2-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251229031753.581664-1-derekjohn.clark@gmail.com> References: <20251229031753.581664-1-derekjohn.clark@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Adds DEVICE_ATTR_[RW|RO|WO]_NAMED macros for adding attributes that reuse the same sysfs name in a driver under separate subdirectories. When dealing with some devices it can be useful to be able to reuse the same name for similar attributes under a different subdirectory. For example, a single logical HID endpoint may provide a configuration interface for multiple physical devices. In such a case it is useful to provide symmetrical attribute names under different subdirectories on the configuration device. The Lenovo Legion Go is one such device, providing configuration to a detachable left controller, detachable right controller, the wireless transmission dongle, and the MCU. It is therefore beneficial to treat each of these as individual devices in the driver, providing a subdirectory for each physical device in the sysfs. As some attributes are reused by each physical device, it provides a much cleaner interface if the same driver can reuse the same attribute name in sysfs while uniquely distinguishing the store/show functions in the driver, rather than repeat string portions. Example new WO attrs: ATTRS{left_handle/reset}=3D=3D"(not readable)" ATTRS{right_handle/reset}=3D=3D"(not readable)" ATTRS{tx_dongle/reset}=3D=3D"(not readable)" vs old WO attrs in a subdir: ATTRS{left_handle/left_handle_reset}=3D=3D"(not readable)" ATTRS{right_handle/right_handle_reset}=3D=3D"(not readable)" ATTRS{tx_dongle/tx_dongle_reset}=3D=3D"(not readable)" or old WO attrs with no subdir: ATTRS{left_handle_reset}=3D=3D"(not readable)" ATTRS{right_handle_reset}=3D=3D"(not readable)" ATTRS{tx_dongle_reset}=3D=3D"(not readable)" While the third option is usable, it doesn't logically break up the physical devices and creates a device directory with over 80 attributes once all attrs are defined. Signed-off-by: Derek J. Clark --- include/linux/device.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index b031ff71a5bd..76f485e6b24c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -189,6 +189,22 @@ ssize_t device_show_string(struct device *dev, struct = device_attribute *attr, #define DEVICE_ATTR_ADMIN_RW(_name) \ struct device_attribute dev_attr_##_name =3D __ATTR_RW_MODE(_name, 0600) =20 +/** + * DEVICE_ATTR_RW_NAMED - Define a read-write device attribute with a sysf= s name + * that differs from the function name. + * @_name: Attribute function preface + * @_attrname: Attribute name as it wil be exposed in the sysfs. + * + * Like DEVICE_ATTR_RW(), but allows for reusing names under separate path= s in + * the same driver. + */ +#define DEVICE_ATTR_RW_NAMED(_name, _attrname) \ + struct device_attribute dev_attr_##_name =3D { \ + .attr =3D { .name =3D _attrname, .mode =3D 0644 }, \ + .show =3D _name##_show, \ + .store =3D _name##_store, \ + } + /** * DEVICE_ATTR_RO - Define a readable device attribute. * @_name: Attribute name. @@ -207,6 +223,21 @@ ssize_t device_show_string(struct device *dev, struct = device_attribute *attr, #define DEVICE_ATTR_ADMIN_RO(_name) \ struct device_attribute dev_attr_##_name =3D __ATTR_RO_MODE(_name, 0400) =20 +/** + * DEVICE_ATTR_RO_NAMED - Define a read-only device attribute with a sysfs= name + * that differs from the function name. + * @_name: Attribute function preface + * @_attrname: Attribute name as it wil be exposed in the sysfs. + * + * Like DEVICE_ATTR_RO(), but allows for reusing names under separate path= s in + * the same driver. + */ +#define DEVICE_ATTR_RO_NAMED(_name, _attrname) \ + struct device_attribute dev_attr_##_name =3D { \ + .attr =3D { .name =3D _attrname, .mode =3D 0444 }, \ + .show =3D _name##_show, \ + } + /** * DEVICE_ATTR_WO - Define an admin-only writable device attribute. * @_name: Attribute name. @@ -216,6 +247,21 @@ ssize_t device_show_string(struct device *dev, struct = device_attribute *attr, #define DEVICE_ATTR_WO(_name) \ struct device_attribute dev_attr_##_name =3D __ATTR_WO(_name) =20 +/** + * DEVICE_ATTR_WO_NAMED - Define a read-only device attribute with a sysfs= name + * that differs from the function name. + * @_name: Attribute function preface + * @_attrname: Attribute name as it wil be exposed in the sysfs. + * + * Like DEVICE_ATTR_WO(), but allows for reusing names under separate path= s in + * the same driver. + */ +#define DEVICE_ATTR_WO_NAMED(_name, _attrname) \ + struct device_attribute dev_attr_##_name =3D { \ + .attr =3D { .name =3D _attrname, .mode =3D 0200 }, \ + .store =3D _name##_store, \ + } + /** * DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned lon= g. * @_name: Attribute name. --=20 2.51.2