Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp136842lqp; Sun, 9 Jun 2024 21:18:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCY/zjF8lH2BjJmWOOFB21FnN26N6bJfCEqPSk0Qm32puefLU5P5TrQN3OwgTgtV4EUDxdYpxRRQA2/7aApAAioyvnrVXLBdOlNDfrPQ== X-Google-Smtp-Source: AGHT+IEHjJ1GSihRW3/UYpHzfh/R1SWL4yxhH4bKpGJQ/Z7mcmEtoHOQNa5zUCCcIwaAxvOj9qNS X-Received: by 2002:a05:6214:4383:b0:6af:c873:8e70 with SMTP id 6a1803df08f44-6b059e17f6emr97538666d6.44.1717993111243; Sun, 09 Jun 2024 21:18:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717993111; cv=pass; d=google.com; s=arc-20160816; b=LOo2moLAHLKtbA0GaFfKLeU0Cfapp4Rc2uw/V47nH0j4ctnFm9JCQtzmsJKaKvQJwB jGn7gJZeSOLCJalBLBPQe/rZmeuTHD4E9vtGshj3el8DG3VgKt+LS2V9Ys8QRl5HYuuM F12dV24uP8JCz8EABRaimBVd+TwsKUJCwHCcvesKxC1uQ+OEHEIHSB7KYYHrvqBGJ8Z2 IqI/iIXk0U4NBSwQ71FTX4Pi6YCLy2OZzw2wCspFhAPoHSaE6RrCYmjVaV2FM7IqhqUT GnPz8cJca/6Ol12qufuhaToPE92Sd0Al1HfUTohBwAQke1LfL/3vr/TmjCNz1bPA6wtb iLzw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=hzhzsPNDuSX6gKE8vpJn202qpdY8rDL50cyxODxHnlQ=; fh=NrZ5g281XcImIdmAIiFdp5Y7G4ZjHceDetVLFjZfcIM=; b=eCyAJ2A8JZYilF8wTMzDDo7i8pROzWSbX2k9SHGHZiIET5HIlAn5erHIjfWVfF+ckD OyOgVRJXdqYnvX6RbGQvld4vL5j3bZWIH6YMUDzgR3XrC9PiOXXnOCLWxGcwP7xTnsC6 GOf5ASWUZBd7HOzBK30RTJ324htRDq7zSGGLdGcGniX8gKdOoSt1Lsg3GEgnnYpMxomF 8wS1a0H8bNDxsLvdzRq07fBtNGSZ2a1hkn8IJmWAZYmhlYptItDKmRNiUSHuLzui4ZWv wLWPiX2RV5GNpzng6uVzZDAFUmbJ01gW4KiltS12AgRed0fK6/Z3zdKsej7CilfOEFlH CTTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=T3vCgylG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-207610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b06e42dc8bsi44917236d6.232.2024.06.09.21.18.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 21:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=T3vCgylG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-207610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 DE28A1C209D9 for ; Mon, 10 Jun 2024 04:18:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8786DBA53; Mon, 10 Jun 2024 04:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T3vCgylG" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 34CEE2594; Mon, 10 Jun 2024 04:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717993100; cv=none; b=lkkmKPcyfN05fwwC8EERlmYKE7fWn3tcDPpyvmKhlNUNIYMInLQIF2cZcNMy7F7M5Bc1ik5z2eb68wmMtubPq0EQS3hqsBVWnj8dixJdUee23l1Q4brSfXAscQZXxmGiVN/hnDCvsmqgSeDuANmvPTOt/RTG+MoHM6CmsnZP4Mk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717993100; c=relaxed/simple; bh=8pqUekQ/VXe34Sof/ze9V8VnC4gCLC5dWK8TF3hQHOI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NWPiMOOb+9TDRTxd1emhtABOvISXSM3+mXWH9cZJNwkVPJzinG6IiISMY1KAA+9XHYG1yxh/h7+Qv+dxSIwihpp3iBP7Mmf4pXSQve4IfayKCfbyecTNp4Zohi0A48Kwqk9+x5UwC5yVe3T43x8qofDi7TzOQRuigufK1ebgxuw= 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=T3vCgylG; arc=none smtp.client-ip=209.85.161.49 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 Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5baeab9fd60so448521eaf.2; Sun, 09 Jun 2024 21:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717993098; x=1718597898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hzhzsPNDuSX6gKE8vpJn202qpdY8rDL50cyxODxHnlQ=; b=T3vCgylGNPv30M8Udh7c7bBHAXQd1CZrNA/aIy4FflKNy841FLYcgIvHL8uofWRoeM 3TQjcg1VuvEHu/oWQsLuoBxTtRbAwUWBJCxtLfY9hv1+Yt0IIgRQ5EAwiYd2VeIsYdn9 0x7pvk9mzdfDQI+W3mYxZqB0Mk/aGBvlJbnT2qIfX2a6jPa64I3xKuZCx1MhaxgDCdu8 gD1fHNqcDqTHAKiKxhtrGeHSoxQTft/VAJAeASSOUTYOZ7ZFDBtDukTyFNLCDK9uyN1J rAN6ZBcgwnd3BWmn9pAOyPjZ3WRRoDROb2gqIDtY1FmOxR7VnDx41DfRidog9eMRlohP UHqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717993098; x=1718597898; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hzhzsPNDuSX6gKE8vpJn202qpdY8rDL50cyxODxHnlQ=; b=QijuexGMU5wemzSNauMWpj7U3SBYHqEJj39VHXAct2pPDoAgKRJ/A0j9teEkFgHYq3 2IDLZ2ic4SJ7F1KH28Pox24tZ3Qkcw/0CGdykuqF3prYbCiW4ABZdiSz8r5Myty5vCyO UzXbCjQV0+TIfpFjlB7/vULdSfzEnl4Am8smOE/AdYtgtdg7zDBrAEPedMw21/XcxNwx m2uhDKwhpt5YRdUdULp0kfV9X+yZimTxUtMsAsI0I3lmiFuagVloDddZzc9fP5kKhu/U NNQ02plw2kxewd3D42LZKyo0NTtbHBW7wqGenuTVGqdv/4e93OZIE6K56WqmavL+NjdZ mgfA== X-Gm-Message-State: AOJu0Ywlw0CRQdBC22W6xVHJBiGRq3O1hLsg4KNE8iOV1QrZYhoPwRgW 7ImT247dXerdpdIPR4qxM6v8jkJiQURViFanAGzsifgZnPNYyuPG1Z3HBg== X-Received: by 2002:a05:6358:72a:b0:19f:4ca6:86c2 with SMTP id e5c5f4694b2df-19f4ca68843mr386940155d.25.1717993097590; Sun, 09 Jun 2024 21:18:17 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:83cc:2314:b3bd:bf64]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6f5a05b83sm30658355ad.249.2024.06.09.21.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 21:18:17 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] Input: ims-pcu - use driver core to instantiate device attributes Date: Sun, 9 Jun 2024 21:18:10 -0700 Message-ID: <20240610041813.722445-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Instead of manually creating driver-specific device attributes set struct usb_driver->dev_groups pointer to have the driver core do it. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/ims-pcu.c | 53 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c index 408a586f8c36..0e61d969662f 100644 --- a/drivers/input/misc/ims-pcu.c +++ b/drivers/input/misc/ims-pcu.c @@ -1466,9 +1466,27 @@ static struct attribute *ims_pcu_ofn_attrs[] = { NULL }; +static umode_t ims_pcu_ofn_is_attr_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct usb_interface *intf = to_usb_interface(dev); + struct ims_pcu *pcu = usb_get_intfdata(intf); + umode_t mode = attr->mode; + + /* + * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor. + */ + if (pcu->bootloader_mode || pcu->device_id == IMS_PCU_PCU_B_DEVICE_ID) + mode = 0; + + return mode; +} + static const struct attribute_group ims_pcu_ofn_attr_group = { - .name = "ofn", - .attrs = ims_pcu_ofn_attrs, + .name = "ofn", + .is_visible = ims_pcu_ofn_is_attr_visible, + .attrs = ims_pcu_ofn_attrs, }; static void ims_pcu_irq(struct urb *urb) @@ -1890,16 +1908,6 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu) /* Device appears to be operable, complete initialization */ pcu->device_no = atomic_inc_return(&device_no); - /* - * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor - */ - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) { - error = sysfs_create_group(&pcu->dev->kobj, - &ims_pcu_ofn_attr_group); - if (error) - return error; - } - error = ims_pcu_setup_backlight(pcu); if (error) return error; @@ -1936,10 +1944,6 @@ static void ims_pcu_destroy_application_mode(struct ims_pcu *pcu) ims_pcu_destroy_gamepad(pcu); ims_pcu_destroy_buttons(pcu); ims_pcu_destroy_backlight(pcu); - - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) - sysfs_remove_group(&pcu->dev->kobj, - &ims_pcu_ofn_attr_group); } } @@ -2031,20 +2035,14 @@ static int ims_pcu_probe(struct usb_interface *intf, if (error) goto err_stop_io; - error = sysfs_create_group(&intf->dev.kobj, &ims_pcu_attr_group); - if (error) - goto err_stop_io; - error = pcu->bootloader_mode ? ims_pcu_init_bootloader_mode(pcu) : ims_pcu_init_application_mode(pcu); if (error) - goto err_remove_sysfs; + goto err_stop_io; return 0; -err_remove_sysfs: - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); err_stop_io: ims_pcu_stop_io(pcu); err_free_buffers: @@ -2070,8 +2068,6 @@ static void ims_pcu_disconnect(struct usb_interface *intf) if (alt->desc.bInterfaceClass != USB_CLASS_COMM) return; - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); - ims_pcu_stop_io(pcu); if (pcu->bootloader_mode) @@ -2130,9 +2126,16 @@ static const struct usb_device_id ims_pcu_id_table[] = { { } }; +static const struct attribute_group *ims_pcu_sysfs_groups[] = { + &ims_pcu_attr_group, + &ims_pcu_ofn_attr_group, + NULL +}; + static struct usb_driver ims_pcu_driver = { .name = "ims_pcu", .id_table = ims_pcu_id_table, + .dev_groups = ims_pcu_sysfs_groups, .probe = ims_pcu_probe, .disconnect = ims_pcu_disconnect, #ifdef CONFIG_PM -- 2.45.2.505.gda0bf45e8d-goog