All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
@ 2015-05-29 11:30 Masahiro Yamada
  2015-05-29 16:16   ` Sören Brinkmann
  2015-06-02 12:56 ` Linus Walleij
  0 siblings, 2 replies; 6+ messages in thread
From: Masahiro Yamada @ 2015-05-29 11:30 UTC (permalink / raw)
  To: linux-gpio
  Cc: Sören Brinkmann, Arnd Bergmann, Masahiro Yamada,
	Linus Walleij, linux-kernel

The pinctrl_register() just returns NULL on error, so the callers
can not know the exact reason of the failure.

Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
-ENOMEM on error of pinctrl_register() , although the error code
might be different from the actual cause of the error.

This new function, pinctrl_register_reason(), helps the drivers get
and return the appropriate error code.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
---
If this patch is accepted, I can send a series to replace
the pinctrl_register() in each driver with pinctrl_register_reason().


 drivers/pinctrl/core.c          | 35 +++++++++++++++++++++++++----------
 include/linux/pinctrl/pinctrl.h |  2 ++
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index f3cf3a8..39c284a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1692,26 +1692,27 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
 }
 
 /**
- * pinctrl_register() - register a pin controller device
+ * pinctrl_register_reason() - register a pin controller device
  * @pctldesc: descriptor for this pin controller
  * @dev: parent device for this pin controller
  * @driver_data: private pin controller data for this pin controller
  */
-struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
-				    struct device *dev, void *driver_data)
+struct pinctrl_dev *pinctrl_register_reason(struct pinctrl_desc *pctldesc,
+					    struct device *dev,
+					    void *driver_data)
 {
 	struct pinctrl_dev *pctldev;
 	int ret;
 
 	if (!pctldesc)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	if (!pctldesc->name)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
 	pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
 	if (pctldev == NULL) {
 		dev_err(dev, "failed to alloc struct pinctrl_dev\n");
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	/* Initialize pin control device struct */
@@ -1724,20 +1725,23 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 	mutex_init(&pctldev->mutex);
 
 	/* check core ops for sanity */
-	if (pinctrl_check_ops(pctldev)) {
+	ret = pinctrl_check_ops(pctldev);
+	if (ret) {
 		dev_err(dev, "pinctrl ops lacks necessary functions\n");
 		goto out_err;
 	}
 
 	/* If we're implementing pinmuxing, check the ops for sanity */
 	if (pctldesc->pmxops) {
-		if (pinmux_check_ops(pctldev))
+		ret = pinmux_check_ops(pctldev);
+		if (ret)
 			goto out_err;
 	}
 
 	/* If we're implementing pinconfig, check the ops for sanity */
 	if (pctldesc->confops) {
-		if (pinconf_check_ops(pctldev))
+		ret = pinconf_check_ops(pctldev);
+		if (ret)
 			goto out_err;
 	}
 
@@ -1783,7 +1787,18 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 out_err:
 	mutex_destroy(&pctldev->mutex);
 	kfree(pctldev);
-	return NULL;
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(pinctrl_register_reason);
+
+struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
+				     struct device *dev, void *driver_data)
+{
+	struct pinctrl_dev *pctldev;
+
+	pctldev = pinctrl_register_reason(pctldesc, dev, driver_data);
+
+	return IS_ERR(pctldev) ? NULL : pctldev;
 }
 EXPORT_SYMBOL_GPL(pinctrl_register);
 
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 9ba59fc..cb05866 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -143,6 +143,8 @@ struct pinctrl_desc {
 /* External interface to pin controller */
 extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 				struct device *dev, void *driver_data);
+extern struct pinctrl_dev *pinctrl_register_reason(struct pinctrl_desc *pctldesc,
+				struct device *dev, void *driver_data);
 extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
 extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
 extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
  2015-05-29 11:30 [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code Masahiro Yamada
@ 2015-05-29 16:16   ` Sören Brinkmann
  2015-06-02 12:56 ` Linus Walleij
  1 sibling, 0 replies; 6+ messages in thread
From: Sören Brinkmann @ 2015-05-29 16:16 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-gpio, Arnd Bergmann, Linus Walleij, linux-kernel

On Fri, 2015-05-29 at 08:30PM +0900, Masahiro Yamada wrote:
> The pinctrl_register() just returns NULL on error, so the callers
> can not know the exact reason of the failure.
> 
> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
> -ENOMEM on error of pinctrl_register() , although the error code
> might be different from the actual cause of the error.
> 
> This new function, pinctrl_register_reason(), helps the drivers get
> and return the appropriate error code.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Sören Brinkmann <soren.brinkmann@xilinx.com>

	Sören
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
@ 2015-05-29 16:16   ` Sören Brinkmann
  0 siblings, 0 replies; 6+ messages in thread
From: Sören Brinkmann @ 2015-05-29 16:16 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-gpio, Arnd Bergmann, Linus Walleij, linux-kernel

On Fri, 2015-05-29 at 08:30PM +0900, Masahiro Yamada wrote:
> The pinctrl_register() just returns NULL on error, so the callers
> can not know the exact reason of the failure.
> 
> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
> -ENOMEM on error of pinctrl_register() , although the error code
> might be different from the actual cause of the error.
> 
> This new function, pinctrl_register_reason(), helps the drivers get
> and return the appropriate error code.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Sören Brinkmann <soren.brinkmann@xilinx.com>

	Sören

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
  2015-05-29 11:30 [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code Masahiro Yamada
  2015-05-29 16:16   ` Sören Brinkmann
@ 2015-06-02 12:56 ` Linus Walleij
  2015-06-02 15:32   ` Masahiro Yamada
  1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2015-06-02 12:56 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-gpio, Sören Brinkmann, Arnd Bergmann, linux-kernel

On Fri, May 29, 2015 at 1:30 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:

> The pinctrl_register() just returns NULL on error, so the callers
> can not know the exact reason of the failure.
>
> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
> -ENOMEM on error of pinctrl_register() , although the error code
> might be different from the actual cause of the error.
>
> This new function, pinctrl_register_reason(), helps the drivers get
> and return the appropriate error code.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>

It should be named pinctrl_register_strict() or something.
"reason" is anyways wrong, should be "cause", but please
use _strict().

> If this patch is accepted, I can send a series to replace
> the pinctrl_register() in each driver with pinctrl_register_reason().

If it is replaced *everywhere* there is no point in keeping
a separate function. Then you should just do a big
patch changing all usage sites and the original function.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
  2015-06-02 12:56 ` Linus Walleij
@ 2015-06-02 15:32   ` Masahiro Yamada
  2015-06-08 13:36     ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Masahiro Yamada @ 2015-06-02 15:32 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio, Sören Brinkmann, Arnd Bergmann, linux-kernel

Hi Linus,


2015-06-02 21:56 GMT+09:00 Linus Walleij <linus.walleij@linaro.org>:
> On Fri, May 29, 2015 at 1:30 PM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>
>> The pinctrl_register() just returns NULL on error, so the callers
>> can not know the exact reason of the failure.
>>
>> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
>> -ENOMEM on error of pinctrl_register() , although the error code
>> might be different from the actual cause of the error.
>>
>> This new function, pinctrl_register_reason(), helps the drivers get
>> and return the appropriate error code.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
>
> It should be named pinctrl_register_strict() or something.
> "reason" is anyways wrong, should be "cause", but please
> use _strict().

OK, I will do it.


>> If this patch is accepted, I can send a series to replace
>> the pinctrl_register() in each driver with pinctrl_register_reason().
>
> If it is replaced *everywhere* there is no point in keeping
> a separate function. Then you should just do a big
> patch changing all usage sites and the original function.


If nobody is opposed to this, I can send a single big patch
replacing all the references.

In that case, we would not need _strict().

My concern is the sudden change of the function interface
will break drivers that are under development out of the source tree.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code
  2015-06-02 15:32   ` Masahiro Yamada
@ 2015-06-08 13:36     ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2015-06-08 13:36 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-gpio, Sören Brinkmann, Arnd Bergmann, linux-kernel

On Tue, Jun 2, 2015 at 5:32 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:

> If nobody is opposed to this, I can send a single big patch
> replacing all the references.
>
> In that case, we would not need _strict().

Yeah just do this.

> My concern is the sudden change of the function interface
> will break drivers that are under development out of the source tree.

Base the patch on my -devel branch so you cover all driver in
development. I will deal with any resulting mess.

Out of tree drivers we do not take into account, they should focus
their efforts on working upstream.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-08 13:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-29 11:30 [PATCH] pinctrl: add pinctrl_register_reason() to return proper error code Masahiro Yamada
2015-05-29 16:16 ` Sören Brinkmann
2015-05-29 16:16   ` Sören Brinkmann
2015-06-02 12:56 ` Linus Walleij
2015-06-02 15:32   ` Masahiro Yamada
2015-06-08 13:36     ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.