From 4452e8ef8c364113495f414d7e6846d74d7eff81 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Mon, 6 May 2024 21:44:49 +0200 Subject: s390/iucv: Provide iucv_alloc_device() / iucv_release_device() Provide iucv_alloc_device() and iucv_release_device() helper functions, which can be used to deduplicate more or less identical IUCV device allocation and release code in four different drivers. Suggested-by: Arnd Bergmann Acked-by: Alexandra Winter Link: https://lore.kernel.org/r/20240506194454.1160315-2-hca@linux.ibm.com Signed-off-by: Heiko Carstens Signed-off-by: Alexander Gordeev --- net/iucv/iucv.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'net') diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c index a4ab615ca3e3..9db7c2c0ae72 100644 --- a/net/iucv/iucv.c +++ b/net/iucv/iucv.c @@ -76,6 +76,41 @@ EXPORT_SYMBOL(iucv_bus); struct device *iucv_root; EXPORT_SYMBOL(iucv_root); +static void iucv_release_device(struct device *device) +{ + kfree(device); +} + +struct device *iucv_alloc_device(const struct attribute_group **attrs, + struct device_driver *driver, + void *priv, const char *fmt, ...) +{ + struct device *dev; + va_list vargs; + int rc; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + goto out_error; + va_start(vargs, fmt); + rc = dev_set_name(dev, fmt, vargs); + va_end(vargs); + if (rc) + goto out_error; + dev->bus = &iucv_bus; + dev->parent = iucv_root; + dev->driver = driver; + dev->groups = attrs; + dev->release = iucv_release_device; + dev_set_drvdata(dev, priv); + return dev; + +out_error: + kfree(dev); + return NULL; +} +EXPORT_SYMBOL(iucv_alloc_device); + static int iucv_available; /* General IUCV interrupt structure */ -- cgit v1.2.3 From effb83572685eaa70d05a8dd6307ca574a11fcf3 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Mon, 6 May 2024 21:44:54 +0200 Subject: s390/iucv: Unexport iucv_root There is no user of iucv_root outside of the core IUCV code left. Therefore remove the EXPORT_SYMBOL. Acked-by: Alexandra Winter Link: https://lore.kernel.org/r/20240506194454.1160315-7-hca@linux.ibm.com Signed-off-by: Heiko Carstens Signed-off-by: Alexander Gordeev --- include/net/iucv/iucv.h | 1 - net/iucv/iucv.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'net') diff --git a/include/net/iucv/iucv.h b/include/net/iucv/iucv.h index b3736e66fe1a..4d114e6d6d23 100644 --- a/include/net/iucv/iucv.h +++ b/include/net/iucv/iucv.h @@ -82,7 +82,6 @@ struct iucv_array { } __attribute__ ((aligned (8))); extern const struct bus_type iucv_bus; -extern struct device *iucv_root; struct device_driver; diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c index 9db7c2c0ae72..2e61f19621ee 100644 --- a/net/iucv/iucv.c +++ b/net/iucv/iucv.c @@ -73,8 +73,7 @@ const struct bus_type iucv_bus = { }; EXPORT_SYMBOL(iucv_bus); -struct device *iucv_root; -EXPORT_SYMBOL(iucv_root); +static struct device *iucv_root; static void iucv_release_device(struct device *device) { -- cgit v1.2.3