Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1342258 > unrolled thread
| Started by | Colin King <colin.king@canonical.com> |
|---|---|
| First post | 2016-02-24 18:40 +0100 |
| Last post | 2016-02-25 19:40 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] pinctrl: lpc18xx: ensure ngroups is initialized at correct place Colin King <colin.king@canonical.com> - 2016-02-24 18:40 +0100
Re: [PATCH] pinctrl: lpc18xx: ensure ngroups is initialized at correct place Joachim Eastwood <manabian@gmail.com> - 2016-02-25 19:40 +0100
| From | Colin King <colin.king@canonical.com> |
|---|---|
| Date | 2016-02-24 18:40 +0100 |
| Subject | [PATCH] pinctrl: lpc18xx: ensure ngroups is initialized at correct place |
| Message-ID | <r5LzR-7Sl-31@gated-at.bofh.it> |
From: Colin Ian King <colin.king@canonical.com>
The initialization of ngroups is occurring at the end of the
first iteration of the outer loop, which means that the
assignment pins[ngroups++] = i is potentially indexing into
a region outside of array pins because ngroups is not initialized.
Instead, initialize ngroups in the inner loop before the first
inner loop iteration.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/pinctrl/pinctrl-lpc18xx.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
index f0bebbe..ed1cfa7 100644
--- a/drivers/pinctrl/pinctrl-lpc18xx.c
+++ b/drivers/pinctrl/pinctrl-lpc18xx.c
@@ -1170,9 +1170,8 @@ static int lpc18xx_create_group_func_map(struct device *dev,
u16 pins[ARRAY_SIZE(lpc18xx_pins)];
int func, ngroups, i;
- for (func = 0; func < FUNC_MAX; ngroups = 0, func++) {
-
- for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
+ for (func = 0; func < FUNC_MAX; func++) {
+ for (ngroups = 0, i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
if (lpc18xx_valid_pin_function(i, func))
pins[ngroups++] = i;
}
--
2.7.0
[toc] | [next] | [standalone]
| From | Joachim Eastwood <manabian@gmail.com> |
|---|---|
| Date | 2016-02-25 19:40 +0100 |
| Subject | Re: [PATCH] pinctrl: lpc18xx: ensure ngroups is initialized at correct place |
| Message-ID | <r68Zr-7W1-9@gated-at.bofh.it> |
| In reply to | #1342258 |
Hi Colin,
On 24 February 2016 at 18:32, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The initialization of ngroups is occurring at the end of the
> first iteration of the outer loop, which means that the
> assignment pins[ngroups++] = i is potentially indexing into
> a region outside of array pins because ngroups is not initialized.
> Instead, initialize ngroups in the inner loop before the first
> inner loop iteration.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/pinctrl/pinctrl-lpc18xx.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
> index f0bebbe..ed1cfa7 100644
> --- a/drivers/pinctrl/pinctrl-lpc18xx.c
> +++ b/drivers/pinctrl/pinctrl-lpc18xx.c
> @@ -1170,9 +1170,8 @@ static int lpc18xx_create_group_func_map(struct device *dev,
> u16 pins[ARRAY_SIZE(lpc18xx_pins)];
> int func, ngroups, i;
>
> - for (func = 0; func < FUNC_MAX; ngroups = 0, func++) {
> -
> - for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
> + for (func = 0; func < FUNC_MAX; func++) {
> + for (ngroups = 0, i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
Good catch!
Reviewed-by: Joachim Eastwood <manabian@gmail.com>
regards,
Joachim Eastwood
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web