Revert "usb: roles: fix NULL pointer issue when put module's reference"

This reverts commit ef982fc410 which is
commit 1c9be13846c0b2abc2480602f8ef421360e1ad9e upstream.

It breaks the Android kernel abi and can be brought back in the future
in an abi-safe way if it is really needed.  It's not a "real" break, and
we can work around it, but this really does not affect Android systems,
so it's safe to drop for now.

Bug: 161946584
Change-Id: Ica8f15560c09d1077c4177fb7710c5a24a563360
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman
2024-04-29 09:39:38 +00:00
parent 784572c0eb
commit f2df20f4c1

View File

@@ -19,7 +19,6 @@ static struct class *role_class;
struct usb_role_switch {
struct device dev;
struct mutex lock; /* device lock*/
struct module *module; /* the module this device depends on */
enum usb_role role;
/* From descriptor */
@@ -134,7 +133,7 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev)
usb_role_switch_match);
if (!IS_ERR_OR_NULL(sw))
WARN_ON(!try_module_get(sw->module));
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
return sw;
}
@@ -156,7 +155,7 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
sw = fwnode_connection_find_match(fwnode, "usb-role-switch",
NULL, usb_role_switch_match);
if (!IS_ERR_OR_NULL(sw))
WARN_ON(!try_module_get(sw->module));
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
return sw;
}
@@ -171,7 +170,7 @@ EXPORT_SYMBOL_GPL(fwnode_usb_role_switch_get);
void usb_role_switch_put(struct usb_role_switch *sw)
{
if (!IS_ERR_OR_NULL(sw)) {
module_put(sw->module);
module_put(sw->dev.parent->driver->owner);
put_device(&sw->dev);
}
}
@@ -188,18 +187,15 @@ struct usb_role_switch *
usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
{
struct device *dev;
struct usb_role_switch *sw = NULL;
if (!fwnode)
return NULL;
dev = class_find_device_by_fwnode(role_class, fwnode);
if (dev) {
sw = to_role_switch(dev);
WARN_ON(!try_module_get(sw->module));
}
if (dev)
WARN_ON(!try_module_get(dev->parent->driver->owner));
return sw;
return dev ? to_role_switch(dev) : NULL;
}
EXPORT_SYMBOL_GPL(usb_role_switch_find_by_fwnode);
@@ -341,7 +337,6 @@ usb_role_switch_register(struct device *parent,
sw->set = desc->set;
sw->get = desc->get;
sw->module = parent->driver->owner;
sw->dev.parent = parent;
sw->dev.fwnode = desc->fwnode;
sw->dev.class = role_class;