linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: update DECLARE_USB_FUNCTION(_INIT) macro
@ 2022-05-09  6:28 Linyu Yuan
  2022-05-09  6:43 ` Greg Kroah-Hartman
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Linyu Yuan @ 2022-05-09  6:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Jack Pham, Linyu Yuan

Take DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc) as example,
it will generate function ffsmod_init/ffsmod_exit()
and variable ffsusb_func.

Add possible character '_' in the macro which will generate
function/variable name in common format, ffs_mod_init/ffs_mod_exit()
and ffs_usb_func.

It will apply to all gadget functions which use this macro.

Also do minor change accordingly to f_loopback.c and f_sourcesink.c.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
---
v2: fix issue report by kernel test robot <lkp@intel.com>

 drivers/usb/gadget/function/f_loopback.c   | 12 +-----------
 drivers/usb/gadget/function/f_sourcesink.c |  6 +++---
 include/linux/usb/composite.h              | 14 +++++++-------
 3 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c
index ae41f55..b0eda4f 100644
--- a/drivers/usb/gadget/function/f_loopback.c
+++ b/drivers/usb/gadget/function/f_loopback.c
@@ -583,16 +583,6 @@ static struct usb_function_instance *loopback_alloc_instance(void)
 
 	return  &lb_opts->func_inst;
 }
-DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc);
-
-int __init lb_modinit(void)
-{
-	return usb_function_register(&Loopbackusb_func);
-}
-
-void __exit lb_modexit(void)
-{
-	usb_function_unregister(&Loopbackusb_func);
-}
+DECLARE_USB_FUNCTION_INIT(Loopback, loopback_alloc_instance, loopback_alloc);
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index 6803cd6..2b7d1f2 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -1270,17 +1270,17 @@ static int __init sslb_modinit(void)
 {
 	int ret;
 
-	ret = usb_function_register(&SourceSinkusb_func);
+	ret = usb_function_register(&SourceSink_usb_func);
 	if (ret)
 		return ret;
 	ret = lb_modinit();
 	if (ret)
-		usb_function_unregister(&SourceSinkusb_func);
+		usb_function_unregister(&SourceSink_usb_func);
 	return ret;
 }
 static void __exit sslb_modexit(void)
 {
-	usb_function_unregister(&SourceSinkusb_func);
+	usb_function_unregister(&SourceSink_usb_func);
 	lb_modexit();
 }
 module_init(sslb_modinit);
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 9d27622..0eac583 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -611,7 +611,7 @@ int usb_add_config_only(struct usb_composite_dev *cdev,
 void usb_remove_function(struct usb_configuration *c, struct usb_function *f);
 
 #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc)		\
-	static struct usb_function_driver _name ## usb_func = {		\
+	static struct usb_function_driver _name ## _usb_func = {	\
 		.name = __stringify(_name),				\
 		.mod  = THIS_MODULE,					\
 		.alloc_inst = _inst_alloc,				\
@@ -621,16 +621,16 @@ void usb_remove_function(struct usb_configuration *c, struct usb_function *f);
 
 #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc)	\
 	DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc)		\
-	static int __init _name ## mod_init(void)			\
+	static int __init _name ## _mod_init(void)			\
 	{								\
-		return usb_function_register(&_name ## usb_func);	\
+		return usb_function_register(&_name ## _usb_func);	\
 	}								\
-	static void __exit _name ## mod_exit(void)			\
+	static void __exit _name ## _mod_exit(void)			\
 	{								\
-		usb_function_unregister(&_name ## usb_func);		\
+		usb_function_unregister(&_name ## _usb_func);		\
 	}								\
-	module_init(_name ## mod_init);					\
-	module_exit(_name ## mod_exit)
+	module_init(_name ## _mod_init);				\
+	module_exit(_name ## _mod_exit)
 
 /* messaging utils */
 #define DBG(d, fmt, args...) \
-- 
2.7.4


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

end of thread, other threads:[~2022-05-09 10:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  6:28 [PATCH v2] usb: gadget: update DECLARE_USB_FUNCTION(_INIT) macro Linyu Yuan
2022-05-09  6:43 ` Greg Kroah-Hartman
2022-05-09  6:51   ` Linyu Yuan (QUIC)
2022-05-09  9:04 ` kernel test robot
2022-05-09  9:24 ` kernel test robot
2022-05-09 10:45 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).