[PATCH v2 1/1] pinctrl: add some error checking for user interfaces

April 10th, 2012 - 12:40 am ET by Dong Aisheng | Report spam
From: Dong Aisheng <dong.aisheng@linaro.org>

This patch can avoid kernel oops in case the mux or config
function is not supported by driver.

Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>

v1-> v2: typo fix

drivers/pinctrl/pinconf.c | 4 ++++
drivers/pinctrl/pinmux.c | 15 +++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index eb3a14f..384dcc1 100644
a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -448,8 +448,12 @@ static void pinconf_dump_pin(struct pinctrl_dev *pctldev,
static int pinconf_pins_show(struct seq_file *s, void *what)
{
struct pinctrl_dev *pctldev = s->private;
+ const struct pinconf_ops *ops = pctldev->desc->confops;
unsigned i, pin;

+ if (!ops || !ops->pin_config_get)
+ return 0;
+
seq_puts(s, "Pin config settings per pin");
seq_puts(s, "Format: pin (name): pinmux setting array");

diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 8849830..c494c37 100644
a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -323,6 +323,11 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
const unsigned *pins;
unsigned num_pins;

+ if (!pmxops) {
+ dev_err(pctldev->dev, "does not support mux function");
+ return -EINVAL;
+ }
+
setting->data.mux.func pinmux_func_name_to_selector(pctldev, map->data.mux.function);
if (setting->data.mux.func < 0)
@@ -481,11 +486,14 @@ static int pinmux_functions_show(struct seq_file *s, void *what)
{
struct pinctrl_dev *pctldev = s->private;
const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
- unsigned nfuncs = pmxops->get_functions_count(pctldev);
+ unsigned nfuncs;
unsigned func_selector = 0;

- mutex_lock(&pinctrl_mutex);
+ if (!pmxops)
+ return 0;

+ mutex_lock(&pinctrl_mutex);
+ nfuncs = pmxops->get_functions_count(pctldev);
while (func_selector < nfuncs) {
const char *func = pmxops->get_function_name(pctldev,
func_selector);
@@ -520,6 +528,9 @@ static int pinmux_pins_show(struct seq_file *s, void *what)
const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
unsigned i, pin;

+ if (!pmxops)
+ return 0;
+
seq_puts(s, "Pinmux settings per pin");
seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?");

1.7.0.4


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
email Follow the discussionReplies 1 replyReplies Make a reply

Replies

#1 Stephen Warren
April 10th, 2012 - 11:10 am ET | Report spam
On 04/09/2012 10:41 PM, Dong Aisheng wrote:
From: Dong Aisheng

This patch can avoid kernel oops in case the mux or config
function is not supported by driver.

Signed-off-by: Dong Aisheng



Acked-by: Stephen Warren
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Similar topics