Skip to content

Commit

Permalink
s390/iucv: Provide iucv_alloc_device() / iucv_release_device()
Browse files Browse the repository at this point in the history
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 <arnd@arndb.de>
Acked-by: Alexandra Winter <wintera@linux.ibm.com>
Link: https://lore.kernel.org/r/20240506194454.1160315-2-hca@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
  • Loading branch information
Heiko Carstens authored and Alexander Gordeev committed May 14, 2024
1 parent 1084562 commit 4452e8e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/net/iucv/iucv.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ struct iucv_array {
extern const struct bus_type iucv_bus;
extern struct device *iucv_root;

struct device_driver;

struct device *iucv_alloc_device(const struct attribute_group **attrs,
struct device_driver *driver, void *priv,
const char *fmt, ...) __printf(4, 5);

/*
* struct iucv_path
* pathid: 16 bit path identification
Expand Down
35 changes: 35 additions & 0 deletions net/iucv/iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 4452e8e

Please sign in to comment.