diff mbox series

[1/8] Input: usbtouchscreen - use driver core to instantiate device attributes

Message ID 20240712051851.3463657-1-dmitry.torokhov@gmail.com
State Accepted
Commit 6797e19d9aa4b0cf134a2b4ccf4db8005cda35cf
Headers show
Series [1/8] Input: usbtouchscreen - use driver core to instantiate device attributes | expand

Commit Message

Dmitry Torokhov July 12, 2024, 5:18 a.m. UTC
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(-)

Comments

Greg KH July 12, 2024, 7:27 a.m. UTC | #1
On Thu, Jul 11, 2024 at 10:18:43PM -0700, Dmitry Torokhov wrote:
> 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(-)

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg KH July 12, 2024, 7:28 a.m. UTC | #2
On Thu, Jul 11, 2024 at 10:18:48PM -0700, Dmitry Torokhov wrote:
> Instead of using a single table containing information about various
> touchscreens and enums to match the driver ID table data with chip
> information define individual per-protocol instances of
> usbtouch_device_info structure and reference them directly from
> the usbtouch_devices ID table. This is simpler, safer, and uses less
> memory in case some protocols are disabled.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg KH July 12, 2024, 7:29 a.m. UTC | #3
On Thu, Jul 11, 2024 at 10:18:46PM -0700, Dmitry Torokhov wrote:
> In preparation of splitting big usbtouch_dev_info table into separate
> per-protocol structures and constifying them move process_pkt() from the
> device info into main drvice structure and set it up in probe().
> We can derive if we should use single- or multi-packet handling based
> on presence of get_pkt_len() method.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg KH July 12, 2024, 7:29 a.m. UTC | #4
On Thu, Jul 11, 2024 at 10:18:44PM -0700, Dmitry Torokhov wrote:
> There already exists perfectly suitable USB_DEVICE_INTERFACE_CLASS
> macro, use it.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff mbox series

Patch

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,
 };