mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-04 13:21:45 +00:00
dsa: Make use of the list of tag drivers
Implement the _get and _put functions to make use of the list of tag drivers. Also, trigger the loading of the module, based on the alias information. The _get function takes a reference on the tag driver, so it cannot be unloaded, and the _put function releases the reference. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> v2: Make tag_driver_register void Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4dad81ee14
commit
3675617531
1 changed files with 34 additions and 5 deletions
|
@ -125,20 +125,49 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
|
||||||
|
|
||||||
const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
|
const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
|
||||||
{
|
{
|
||||||
|
struct dsa_tag_driver *dsa_tag_driver;
|
||||||
const struct dsa_device_ops *ops;
|
const struct dsa_device_ops *ops;
|
||||||
|
char module_name[128];
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
if (tag_protocol >= DSA_TAG_LAST)
|
snprintf(module_name, 127, "%s%d", DSA_TAG_DRIVER_ALIAS,
|
||||||
return ERR_PTR(-EINVAL);
|
tag_protocol);
|
||||||
ops = dsa_device_ops[tag_protocol];
|
|
||||||
|
|
||||||
if (!ops)
|
request_module(module_name);
|
||||||
return ERR_PTR(-ENOPROTOOPT);
|
|
||||||
|
mutex_lock(&dsa_tag_drivers_lock);
|
||||||
|
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
|
||||||
|
ops = dsa_tag_driver->ops;
|
||||||
|
if (ops->proto == tag_protocol) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
if (!try_module_get(dsa_tag_driver->owner))
|
||||||
|
ops = ERR_PTR(-ENOPROTOOPT);
|
||||||
|
} else {
|
||||||
|
ops = ERR_PTR(-ENOPROTOOPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&dsa_tag_drivers_lock);
|
||||||
|
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsa_tag_driver_put(const struct dsa_device_ops *ops)
|
void dsa_tag_driver_put(const struct dsa_device_ops *ops)
|
||||||
{
|
{
|
||||||
|
struct dsa_tag_driver *dsa_tag_driver;
|
||||||
|
|
||||||
|
mutex_lock(&dsa_tag_drivers_lock);
|
||||||
|
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
|
||||||
|
if (dsa_tag_driver->ops == ops) {
|
||||||
|
module_put(dsa_tag_driver->owner);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutex_unlock(&dsa_tag_drivers_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dev_is_class(struct device *dev, void *class)
|
static int dev_is_class(struct device *dev, void *class)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue