* [PATCH] mux: core: fix double get_device()
@ 2017-12-28 23:22 Peter Rosin
2017-12-28 23:22 ` [PATCH] mux: add SPDX identifiers to all mux source files Peter Rosin
0 siblings, 1 reply; 4+ messages in thread
From: Peter Rosin @ 2017-12-28 23:22 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Hans de Goede, Peter Rosin, linux-kernel
From: Hans de Goede <hdegoede@redhat.com>
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>
---
drivers/mux/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Hi Greg,
Here is a fix for 4.15, and it should perhaps also go to
stable?
It's been in -next for a couple of weeks w/o complaints.
Cheers,
Peter
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 2260063b0ea8..6e5cf9d9cd99 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -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);
--
2.11.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH] mux: add SPDX identifiers to all mux source files
2017-12-28 23:22 [PATCH] mux: core: fix double get_device() Peter Rosin
@ 2017-12-28 23:22 ` Peter Rosin
0 siblings, 0 replies; 4+ messages in thread
From: Peter Rosin @ 2017-12-28 23:22 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Peter Rosin, linux-kernel
Remove all free-text license texts.
This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text.
No copyright headers or other non-license-description text was removed.
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Peter Rosin <peda@axentia.se>
---
drivers/mux/Kconfig | 1 +
drivers/mux/Makefile | 1 +
drivers/mux/adg792a.c | 5 +----
drivers/mux/core.c | 5 +----
drivers/mux/gpio.c | 5 +----
drivers/mux/mmio.c | 5 +----
include/linux/mux/consumer.h | 5 +----
include/linux/mux/driver.h | 5 +----
8 files changed, 8 insertions(+), 24 deletions(-)
Hi Greg,
Here is a patch for 4.16. I have some documentation updates
as well, but I think Corbet is taking those. Not 100% sure
though, but I didn't want to risk this one being stalled
over that with all the holidays etc.
Cheers,
Peter
diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
index 19e4e904c9bf..6241678e99af 100644
--- a/drivers/mux/Kconfig
+++ b/drivers/mux/Kconfig
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
#
# Multiplexer devices
#
diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
index 0e1e59760e3f..c3d883955fd5 100644
--- a/drivers/mux/Makefile
+++ b/drivers/mux/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
#
# Makefile for multiplexer devices.
#
diff --git a/drivers/mux/adg792a.c b/drivers/mux/adg792a.c
index 12aa221ab90d..6a8725cf3d71 100644
--- a/drivers/mux/adg792a.c
+++ b/drivers/mux/adg792a.c
@@ -1,13 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* Multiplexer driver for Analog Devices ADG792A/G Triple 4:1 mux
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#include <linux/err.h>
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 6e5cf9d9cd99..d1271c1ee23c 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -1,13 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* Multiplexer subsystem
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#define pr_fmt(fmt) "mux-core: " fmt
diff --git a/drivers/mux/gpio.c b/drivers/mux/gpio.c
index 468bf1709606..6fdd9316db8b 100644
--- a/drivers/mux/gpio.c
+++ b/drivers/mux/gpio.c
@@ -1,13 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* GPIO-controlled multiplexer driver
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#include <linux/err.h>
diff --git a/drivers/mux/mmio.c b/drivers/mux/mmio.c
index 37c1de359a70..935ac44aa209 100644
--- a/drivers/mux/mmio.c
+++ b/drivers/mux/mmio.c
@@ -1,11 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* MMIO register bitfield-controlled multiplexer driver
*
* Copyright (C) 2017 Pengutronix, Philipp Zabel <kernel@pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#include <linux/bitops.h>
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index ea96d4c82be7..5fc6bb2fefad 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -1,13 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
/*
* mux/consumer.h - definitions for the multiplexer consumer interface
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#ifndef _LINUX_MUX_CONSUMER_H
diff --git a/include/linux/mux/driver.h b/include/linux/mux/driver.h
index 35c3579c3304..627a2c6bc02d 100644
--- a/include/linux/mux/driver.h
+++ b/include/linux/mux/driver.h
@@ -1,13 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
/*
* mux/driver.h - definitions for the multiplexer driver interface
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
#ifndef _LINUX_MUX_DRIVER_H
--
2.11.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mux: core: Fix double get_device()
@ 2017-08-31 15:22 Hans de Goede
2017-08-31 21:57 ` Peter Rosin
0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2017-08-31 15:22 UTC (permalink / raw)
To: Peter Rosin; +Cc: Hans de Goede, Greg Kroah-Hartman, linux-kernel
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.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/mux/core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 7aa656ac8fb5..8864cc745506 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -433,7 +433,7 @@ static int of_dev_node_match(struct device *dev, const void *data)
return dev->of_node == data;
}
-static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
+static struct mux_chip *of_get_mux_chip_by_node(struct device_node *np)
{
struct device *dev;
@@ -471,7 +471,7 @@ static struct mux_control *of_mux_control_get(struct device *dev,
return ERR_PTR(ret);
}
- mux_chip = of_find_mux_chip_by_node(args.np);
+ mux_chip = of_get_mux_chip_by_node(args.np);
of_node_put(args.np);
if (!mux_chip)
return ERR_PTR(-EPROBE_DEFER);
@@ -480,6 +480,7 @@ static struct mux_control *of_mux_control_get(struct device *dev,
(!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);
}
@@ -490,10 +491,10 @@ static struct mux_control *of_mux_control_get(struct device *dev,
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];
}
--
2.13.4
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mux: core: Fix double get_device()
2017-08-31 15:22 [PATCH] mux: core: Fix double get_device() Hans de Goede
@ 2017-08-31 21:57 ` Peter Rosin
0 siblings, 0 replies; 4+ messages in thread
From: Peter Rosin @ 2017-08-31 21:57 UTC (permalink / raw)
To: Hans de Goede; +Cc: Greg Kroah-Hartman, linux-kernel
On 2017-08-31 17:22, Hans de Goede wrote:
> 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).
Oops, yes that's right.
> Also rename of_find_mux_chip_by_node to of_get_mux_chip_by_node to
> make it clear that it returns a reference.
By that logic, you sign up for a lot of churn, these are but a few
examples:
s/of_find_device_by_node/of_get_device_by_node/
s/of_find_regulator_by_node/of_get_regulator_by_node/
s/of_find_spi_controller_by_node/of_get_spi_controller_by_node/
s/of_find_i2c_device_by_node/of_get_i2c_device_by_node/
s/of_find_i2c_adapter_by_node/of_get_i2c_adapter_by_node/
But there's already an of_get_i2c_adapter_by_node (that has slightly
different semantics) -> get ready for pushback.
So, I don't like the rename and would be much happier with a comment
above the function that the returned ref is supposed to be put away
when done.
Cheers,
Peter
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/mux/core.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 7aa656ac8fb5..8864cc745506 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -433,7 +433,7 @@ static int of_dev_node_match(struct device *dev, const void *data)
> return dev->of_node == data;
> }
>
> -static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
> +static struct mux_chip *of_get_mux_chip_by_node(struct device_node *np)
> {
> struct device *dev;
>
> @@ -471,7 +471,7 @@ static struct mux_control *of_mux_control_get(struct device *dev,
> return ERR_PTR(ret);
> }
>
> - mux_chip = of_find_mux_chip_by_node(args.np);
> + mux_chip = of_get_mux_chip_by_node(args.np);
> of_node_put(args.np);
> if (!mux_chip)
> return ERR_PTR(-EPROBE_DEFER);
> @@ -480,6 +480,7 @@ static struct mux_control *of_mux_control_get(struct device *dev,
> (!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);
> }
>
> @@ -490,10 +491,10 @@ static struct mux_control *of_mux_control_get(struct device *dev,
> 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];
> }
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-12-28 23:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-28 23:22 [PATCH] mux: core: fix double get_device() Peter Rosin
2017-12-28 23:22 ` [PATCH] mux: add SPDX identifiers to all mux source files Peter Rosin
-- strict thread matches above, loose matches on Subject: below --
2017-08-31 15:22 [PATCH] mux: core: Fix double get_device() Hans de Goede
2017-08-31 21:57 ` Peter Rosin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®