Implement cdev_device_add() and cdev_device_del() in the LinuxKPI.

Sponsored by:	Mellanox Technologies // NVIDIA Networking

(cherry picked from commit b8f113cab9)
This commit is contained in:
Hans Petter Selasky 2021-05-11 20:51:59 +02:00
parent 303bef2a07
commit fba2292d65
2 changed files with 47 additions and 2 deletions

View file

@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2021 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -38,6 +38,7 @@
#include <asm/atomic-long.h>
struct device;
struct file_operations;
struct inode;
struct module;
@ -143,6 +144,14 @@ cdev_del(struct linux_cdev *cdev)
struct linux_cdev *linux_find_cdev(const char *name, unsigned major, unsigned minor);
int linux_cdev_device_add(struct linux_cdev *, struct device *);
void linux_cdev_device_del(struct linux_cdev *, struct device *);
#define cdev_device_add(...) \
linux_cdev_device_add(__VA_ARGS__)
#define cdev_device_del(...) \
linux_cdev_device_del(__VA_ARGS__)
#define cdev linux_cdev
#endif /* _LINUX_CDEV_H_ */

View file

@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2018 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2021 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -2235,6 +2235,42 @@ linux_cdev_static_release(struct kobject *kobj)
kobject_put(kobj->parent);
}
int
linux_cdev_device_add(struct linux_cdev *ldev, struct device *dev)
{
int ret;
if (dev->devt != 0) {
/* Set parent kernel object. */
ldev->kobj.parent = &dev->kobj;
/*
* Unlike Linux we require the kobject of the
* character device structure to have a valid name
* before calling this function:
*/
if (ldev->kobj.name == NULL)
return (-EINVAL);
ret = cdev_add(ldev, dev->devt, 1);
if (ret)
return (ret);
}
ret = device_add(dev);
if (ret != 0 && dev->devt != 0)
cdev_del(ldev);
return (ret);
}
void
linux_cdev_device_del(struct linux_cdev *ldev, struct device *dev)
{
device_del(dev);
if (dev->devt != 0)
cdev_del(ldev);
}
static void
linux_destroy_dev(struct linux_cdev *ldev)
{