All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] Input: usbtouchscreen - use driver core to instantiate device attributes
@ 2024-07-12  5:18 Dmitry Torokhov
  2024-07-12  5:18 ` [PATCH 2/8] Input: usbtouchscreen - remove custom USB_DEVICE_HID_CLASS macro Dmitry Torokhov
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2024-07-12  5:18 UTC (permalink / raw)
  To: linux-input; +Cc: Greg KH, linux-kernel

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 <dmitry.torokhov@gmail.com>
---
 drivers/input/touchscreen/usbtouchscreen.c | 31 +++++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index dd6b12c6dc58..8b3a6e7fd990 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -240,6 +240,7 @@ static const struct usb_device_id usbtouch_devices[] = {
 	{}
 };
 
+static struct usbtouch_device_info usbtouch_dev_info[];
 
 /*****************************************************************************
  * e2i Part
@@ -466,7 +467,19 @@ static struct attribute *mtouch_attrs[] = {
 	NULL
 };
 
+static bool mtouch_group_visible(struct kobject *kobj)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+
+	return usbtouch->type == &usbtouch_dev_info[DEVTYPE_3M];
+}
+
+DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(mtouch);
+
 static const struct attribute_group mtouch_attr_group = {
+	.is_visible = SYSFS_GROUP_VISIBLE(mtouch),
 	.attrs = mtouch_attrs,
 };
 
@@ -506,21 +519,12 @@ static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch)
 static int mtouch_alloc(struct usbtouch_usb *usbtouch)
 {
 	struct mtouch_priv *priv;
-	int ret;
 
 	priv = kmalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
 	usbtouch->priv = priv;
-	ret = sysfs_create_group(&usbtouch->interface->dev.kobj,
-				 &mtouch_attr_group);
-	if (ret) {
-		kfree(usbtouch->priv);
-		usbtouch->priv = NULL;
-		return ret;
-	}
-
 	return 0;
 }
 
@@ -571,7 +575,6 @@ static void mtouch_exit(struct usbtouch_usb *usbtouch)
 {
 	struct mtouch_priv *priv = usbtouch->priv;
 
-	sysfs_remove_group(&usbtouch->interface->dev.kobj, &mtouch_attr_group);
 	kfree(priv);
 }
 #endif
@@ -1842,6 +1845,13 @@ static void usbtouch_disconnect(struct usb_interface *intf)
 	kfree(usbtouch);
 }
 
+static const struct attribute_group *usbtouch_groups[] = {
+#ifdef CONFIG_TOUCHSCREEN_USB_3M
+	&mtouch_attr_group,
+#endif
+	NULL
+};
+
 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
 
 static struct usb_driver usbtouch_driver = {
@@ -1852,6 +1862,7 @@ static struct usb_driver usbtouch_driver = {
 	.resume		= usbtouch_resume,
 	.reset_resume	= usbtouch_reset_resume,
 	.id_table	= usbtouch_devices,
+	.dev_groups	= usbtouch_groups,
 	.supports_autosuspend = 1,
 };
 
-- 
2.45.2.993.g49e7a77208-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-07-12  7:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12  5:18 [PATCH 1/8] Input: usbtouchscreen - use driver core to instantiate device attributes Dmitry Torokhov
2024-07-12  5:18 ` [PATCH 2/8] Input: usbtouchscreen - remove custom USB_DEVICE_HID_CLASS macro Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 3/8] Input: usbtouchscreen - move the driver ID table Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 4/8] Input: usbtouchscreen - move process_pkt() into main device structure Dmitry Torokhov
2024-07-12  7:29   ` Greg KH
2024-07-12  5:18 ` [PATCH 5/8] Input: usbtouchscreen - constify usbtouch_dev_info table Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 6/8] Input: usbtouchscreen - split device info table into individual pieces Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 7/8] Input: usbtouchscreen - use guard notation when acquiring mutexes Dmitry Torokhov
2024-07-12  7:28   ` Greg KH
2024-07-12  5:18 ` [PATCH 8/8] Input: usbtouchscreen - switch to using __free() cleanup facility Dmitry Torokhov
2024-07-12  7:27   ` Greg KH
2024-07-12  7:27 ` [PATCH 1/8] Input: usbtouchscreen - use driver core to instantiate device attributes Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.