Skip to content

Commit

Permalink
counter: remove old and now unused registration API
Browse files Browse the repository at this point in the history
Usage of counter_register() yields issues in device lifetime tracking. All
drivers were converted to the new API, so the old one can go away.

Reviewed-by: Jonathan Cameron <[email protected]>
Acked-by: William Breathitt Gray <[email protected]>
Signed-off-by: Uwe Kleine-König <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Uwe Kleine-König authored and gregkh committed Dec 30, 2021
1 parent 02758cb commit f2ee475
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 108 deletions.
100 changes: 4 additions & 96 deletions drivers/counter/counter-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ static void counter_device_release(struct device *dev)
counter_chrdev_remove(counter);
ida_free(&counter_ida, dev->id);

if (!counter->legacy_device)
kfree(container_of(counter, struct counter_device_allochelper, counter));
kfree(container_of(counter, struct counter_device_allochelper, counter));
}

static struct device_type counter_device_type = {
Expand All @@ -67,76 +66,13 @@ static dev_t counter_devt;
*/
void *counter_priv(const struct counter_device *const counter)
{
if (counter->legacy_device) {
return counter->priv;
} else {
struct counter_device_allochelper *ch =
container_of(counter, struct counter_device_allochelper, counter);
struct counter_device_allochelper *ch =
container_of(counter, struct counter_device_allochelper, counter);

return &ch->privdata;
}
return &ch->privdata;
}
EXPORT_SYMBOL_GPL(counter_priv);

/**
* counter_register - register Counter to the system
* @counter: pointer to Counter to register
*
* This function registers a Counter to the system. A sysfs "counter" directory
* will be created and populated with sysfs attributes correlating with the
* Counter Signals, Synapses, and Counts respectively.
*
* RETURNS:
* 0 on success, negative error number on failure.
*/
int counter_register(struct counter_device *const counter)
{
struct device *const dev = &counter->dev;
int id;
int err;

counter->legacy_device = true;

/* Acquire unique ID */
id = ida_alloc(&counter_ida, GFP_KERNEL);
if (id < 0)
return id;

mutex_init(&counter->ops_exist_lock);

/* Configure device structure for Counter */
dev->id = id;
dev->type = &counter_device_type;
dev->bus = &counter_bus_type;
dev->devt = MKDEV(MAJOR(counter_devt), id);
if (counter->parent) {
dev->parent = counter->parent;
dev->of_node = counter->parent->of_node;
}
device_initialize(dev);

err = counter_sysfs_add(counter);
if (err < 0)
goto err_free_id;

err = counter_chrdev_add(counter);
if (err < 0)
goto err_free_id;

err = cdev_device_add(&counter->chrdev, dev);
if (err < 0)
goto err_remove_chrdev;

return 0;

err_remove_chrdev:
counter_chrdev_remove(counter);
err_free_id:
put_device(dev);
return err;
}
EXPORT_SYMBOL_GPL(counter_register);

/**
* counter_alloc - allocate a counter_device
* @sizeof_priv: size of the driver private data
Expand Down Expand Up @@ -245,9 +181,6 @@ void counter_unregister(struct counter_device *const counter)
wake_up(&counter->events_wait);

mutex_unlock(&counter->ops_exist_lock);

if (counter->legacy_device)
put_device(&counter->dev);
}
EXPORT_SYMBOL_GPL(counter_unregister);

Expand All @@ -256,31 +189,6 @@ static void devm_counter_release(void *counter)
counter_unregister(counter);
}

/**
* devm_counter_register - Resource-managed counter_register
* @dev: device to allocate counter_device for
* @counter: pointer to Counter to register
*
* Managed counter_register. The Counter registered with this function is
* automatically unregistered on driver detach. This function calls
* counter_register internally. Refer to that function for more information.
*
* RETURNS:
* 0 on success, negative error number on failure.
*/
int devm_counter_register(struct device *dev,
struct counter_device *const counter)
{
int err;

err = counter_register(counter);
if (err < 0)
return err;

return devm_add_action_or_reset(dev, devm_counter_release, counter);
}
EXPORT_SYMBOL_GPL(devm_counter_register);

static void devm_counter_put(void *counter)
{
counter_put(counter);
Expand Down
12 changes: 0 additions & 12 deletions include/linux/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ struct counter_device {
struct counter_comp *ext;
size_t num_ext;

void *priv;

struct device dev;
struct cdev chrdev;
struct list_head events_list;
Expand All @@ -327,25 +325,15 @@ struct counter_device {
spinlock_t events_in_lock;
struct mutex events_out_lock;
struct mutex ops_exist_lock;

/*
* This can go away once all drivers are converted to
* counter_alloc()/counter_add().
*/
bool legacy_device;
};

void *counter_priv(const struct counter_device *const counter);

int counter_register(struct counter_device *const counter);

struct counter_device *counter_alloc(size_t sizeof_priv);
void counter_put(struct counter_device *const counter);
int counter_add(struct counter_device *const counter);

void counter_unregister(struct counter_device *const counter);
int devm_counter_register(struct device *dev,
struct counter_device *const counter);
struct counter_device *devm_counter_alloc(struct device *dev,
size_t sizeof_priv);
int devm_counter_add(struct device *dev,
Expand Down

0 comments on commit f2ee475

Please sign in to comment.