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

This reverts commit 0158216805 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.

Bug: 161946584
Change-Id: I092d81a7ad00ebe0d0c16509b5789ea0b7de29e4
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman
2024-05-02 07:43:57 +00:00
parent 706f6a46d8
commit 601ccd855a

View File

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