Skip to content

Commit aa1f10e

Browse files
jwrdegoedegregkh
authored andcommitted
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). Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Peter Rosin <peda@axentia.se> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 06e7e77 commit aa1f10e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎drivers/mux/core.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ static int of_dev_node_match(struct device *dev, const void *data)
413413
return dev->of_node == data;
414414
}
415415

416+
/* Note this function returns a reference to the mux_chip dev. */
416417
static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
417418
{
418419
struct device *dev;
@@ -466,6 +467,7 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
466467
(!args.args_count && (mux_chip->controllers > 1))) {
467468
dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n",
468469
np, args.np);
470+
put_device(&mux_chip->dev);
469471
return ERR_PTR(-EINVAL);
470472
}
471473

@@ -476,10 +478,10 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
476478
if (controller >= mux_chip->controllers) {
477479
dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n",
478480
np, controller, args.np);
481+
put_device(&mux_chip->dev);
479482
return ERR_PTR(-EINVAL);
480483
}
481484

482-
get_device(&mux_chip->dev);
483485
return &mux_chip->mux[controller];
484486
}
485487
EXPORT_SYMBOL_GPL(mux_control_get);

0 commit comments

Comments
 (0)