reset: warn on invalid input to reset_control_reset/assert/deassert/status
authorPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 20 Jun 2016 11:05:14 +0000 (13:05 +0200)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Wed, 24 Aug 2016 13:21:36 +0000 (15:21 +0200)
Instead of potentially crashing, dump a backtrace and return -EINVAL if
rstc is NULL or an error code.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
drivers/reset/core.c

index 395dc9ce492e775336b2a17856dc4392981b4bf8..b8ae1dbd4c17dac9aaf36b7f119cced2f7b5500b 100644 (file)
@@ -138,7 +138,8 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);
  */
 int reset_control_reset(struct reset_control *rstc)
 {
-       if (WARN_ON(rstc->shared))
+       if (WARN_ON(IS_ERR_OR_NULL(rstc)) ||
+           WARN_ON(rstc->shared))
                return -EINVAL;
 
        if (rstc->rcdev->ops->reset)
@@ -161,6 +162,9 @@ EXPORT_SYMBOL_GPL(reset_control_reset);
  */
 int reset_control_assert(struct reset_control *rstc)
 {
+       if (WARN_ON(IS_ERR_OR_NULL(rstc)))
+               return -EINVAL;
+
        if (!rstc->rcdev->ops->assert)
                return -ENOTSUPP;
 
@@ -184,6 +188,9 @@ EXPORT_SYMBOL_GPL(reset_control_assert);
  */
 int reset_control_deassert(struct reset_control *rstc)
 {
+       if (WARN_ON(IS_ERR_OR_NULL(rstc)))
+               return -EINVAL;
+
        if (!rstc->rcdev->ops->deassert)
                return -ENOTSUPP;
 
@@ -204,6 +211,9 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);
  */
 int reset_control_status(struct reset_control *rstc)
 {
+       if (WARN_ON(IS_ERR_OR_NULL(rstc)))
+               return -EINVAL;
+
        if (rstc->rcdev->ops->status)
                return rstc->rcdev->ops->status(rstc->rcdev, rstc->id);