|
20 | 20 | struct mdio_mux_gpio_state {
|
21 | 21 | struct gpio_descs *gpios;
|
22 | 22 | void *mux_handle;
|
| 23 | + int values[]; |
23 | 24 | };
|
24 | 25 |
|
25 | 26 | static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
|
26 | 27 | void *data)
|
27 | 28 | {
|
28 | 29 | struct mdio_mux_gpio_state *s = data;
|
29 |
| - int values[s->gpios->ndescs]; |
30 | 30 | unsigned int n;
|
31 | 31 |
|
32 | 32 | if (current_child == desired_child)
|
33 | 33 | return 0;
|
34 | 34 |
|
35 | 35 | for (n = 0; n < s->gpios->ndescs; n++)
|
36 |
| - values[n] = (desired_child >> n) & 1; |
| 36 | + s->values[n] = (desired_child >> n) & 1; |
37 | 37 |
|
38 | 38 | gpiod_set_array_value_cansleep(s->gpios->ndescs, s->gpios->desc,
|
39 |
| - values); |
| 39 | + s->values); |
40 | 40 |
|
41 | 41 | return 0;
|
42 | 42 | }
|
43 | 43 |
|
44 | 44 | static int mdio_mux_gpio_probe(struct platform_device *pdev)
|
45 | 45 | {
|
46 | 46 | struct mdio_mux_gpio_state *s;
|
| 47 | + struct gpio_descs *gpios; |
47 | 48 | int r;
|
48 | 49 |
|
49 |
| - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); |
50 |
| - if (!s) |
| 50 | + gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW); |
| 51 | + if (IS_ERR(gpios)) |
| 52 | + return PTR_ERR(gpios); |
| 53 | + |
| 54 | + s = devm_kzalloc(&pdev->dev, struct_size(s, values, gpios->ndescs), |
| 55 | + GFP_KERNEL); |
| 56 | + if (!s) { |
| 57 | + gpiod_put_array(gpios); |
51 | 58 | return -ENOMEM;
|
| 59 | + } |
52 | 60 |
|
53 |
| - s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW); |
54 |
| - if (IS_ERR(s->gpios)) |
55 |
| - return PTR_ERR(s->gpios); |
| 61 | + s->gpios = gpios; |
56 | 62 |
|
57 | 63 | r = mdio_mux_init(&pdev->dev, pdev->dev.of_node,
|
58 | 64 | mdio_mux_gpio_switch_fn, &s->mux_handle, s, NULL);
|
|
0 commit comments