Skip to content

Commit b339e1d

Browse files
krzklinusw
authored andcommitted
pinctrl: tb10x: Simplify locking with guard()
Simplify error handling (less code in error case) over locks with guard(). Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Signed-off-by: Linus Walleij <linusw@kernel.org>
1 parent 708adef commit b339e1d

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

drivers/pinctrl/pinctrl-tb10x.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
607607
int muxmode = -1;
608608
int i;
609609

610-
mutex_lock(&state->mutex);
610+
guard(mutex)(&state->mutex);
611611

612612
/*
613613
* Figure out to which port the requested GPIO belongs and how to
@@ -642,7 +642,6 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
642642
* Error: The requested pin is already
643643
* used for something else.
644644
*/
645-
mutex_unlock(&state->mutex);
646645
return -EBUSY;
647646
}
648647
break;
@@ -667,8 +666,6 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
667666
if (muxport >= 0)
668667
tb10x_pinctrl_set_config(state, muxport, muxmode);
669668

670-
mutex_unlock(&state->mutex);
671-
672669
return 0;
673670
}
674671

@@ -695,34 +692,28 @@ static int tb10x_pctl_set_mux(struct pinctrl_dev *pctl,
695692
if (grp->port < 0)
696693
return 0;
697694

698-
mutex_lock(&state->mutex);
695+
guard(mutex)(&state->mutex);
699696

700697
/*
701698
* Check if the requested function is compatible with previously
702699
* requested functions.
703700
*/
704701
if (state->ports[grp->port].count
705-
&& (state->ports[grp->port].mode != grp->mode)) {
706-
mutex_unlock(&state->mutex);
702+
&& (state->ports[grp->port].mode != grp->mode))
707703
return -EBUSY;
708-
}
709704

710705
/*
711706
* Check if the requested function is compatible with previously
712707
* requested GPIOs.
713708
*/
714709
for (i = 0; i < grp->pincnt; i++)
715-
if (test_bit(grp->pins[i], state->gpios)) {
716-
mutex_unlock(&state->mutex);
710+
if (test_bit(grp->pins[i], state->gpios))
717711
return -EBUSY;
718-
}
719712

720713
tb10x_pinctrl_set_config(state, grp->port, grp->mode);
721714

722715
state->ports[grp->port].count++;
723716

724-
mutex_unlock(&state->mutex);
725-
726717
return 0;
727718
}
728719

0 commit comments

Comments
 (0)