mux: core: Fix double get_device()
PATCH RESEND v2 1/1 mux: core: Fix double get_device()
class_find_device already does a get_device on the returned device. So the device returned by of_find_mux_chip_by_node is already referenced and we should not reference it again (and unref it on error).
Also rename of_find_mux_chip_by_node to of_get_mux_chip_by_node to make it clear that it returns a reference.
---
Changes in v2:
-Do not rename of_find_mux_chip_by_node
--- drivers/mux/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mux/core.c +3 -1
@@ -413,6 +413,7 @@ static int of_dev_node_match(struct device *dev, const void *data)return dev->of_node == data; } +/* Note this function returns a reference to the mux_chip dev. */ static struct mux_chip *of_find_mux_chip_by_node (struct device_node *np) {struct device *dev;
@@ -466,6 +467,7 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) (!args.args_count && (mux_chip->controllers > 1))) {dev_err (dev,"%pOF: wrong #mux-control-cells for %pOF\n" , np, args.np); +put_device (&mux_chip->dev);return ERR_PTR (-EINVAL ); }
@@ -476,10 +478,10 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)if (controller >= mux_chip->controllers) {dev_err (dev,"%pOF: bad mux controller %u specified in %pOF\n" , np, controller, args.np); +put_device (&mux_chip->dev);return ERR_PTR (-EINVAL ); } -get_device (&mux_chip->dev);return &mux_chip->mux[controller]; }EXPORT_SYMBOL_GPL (mux_control_get);
Signature · 1 line
2.14.3
Quoted 6 lines · Hans de Goede
class_find_devicealready does aget_deviceon the returned device. So the device returned byof_find_mux_chip_by_nodeis already referenced and we should not reference it again (and unref it on error).Also rename
of_find_mux_chip_by_nodetoof_get_mux_chip_by_nodeto make it clear that it returns a reference.
Yep, I forgot. Sorry about that. I'll try to do better this time...
Cheers,
Peter
Quoted 41 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-Do not rename of_find_mux_chip_by_node --- drivers/mux/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/mux/core.c +3
-1@@ -413,6 +413,7 @@ static int of_dev_node_match(struct device *dev, const void *data)return dev->of_node == data; } +/* Note this function returns a reference to the mux_chip dev. */ static struct mux_chip *of_find_mux_chip_by_node (struct device_node *np) {struct device *dev;@@ -466,6 +467,7 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) (!args.args_count && (mux_chip->controllers > 1))) {dev_err (dev,"%pOF: wrong #mux-control-cells for %pOF\n" , np, args.np); +put_device (&mux_chip->dev);return ERR_PTR (-EINVAL ); }@@ -476,10 +478,10 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)if (controller >= mux_chip->controllers) {dev_err (dev,"%pOF: bad mux controller %u specified in %pOF\n" , np, controller, args.np); +put_device (&mux_chip->dev);return ERR_PTR (-EINVAL ); } -get_device (&mux_chip->dev);return &mux_chip->mux[controller]; }EXPORT_SYMBOL_GPL (mux_control_get);