hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/pinctrl/pinctrl-tb10x.c
....@@ -1,22 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Abilis Systems TB10x pin control driver
34 *
45 * Copyright (C) Abilis Systems 2012
56 *
67 * Author: Christian Ruppert <christian.ruppert@abilis.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
208 */
219
2210 #include <linux/stringify.h>
....@@ -483,22 +471,22 @@
483471 * @base: register set base address.
484472 * @pingroups: pointer to an array of the pin groups this driver manages.
485473 * @pinfuncgrpcnt: number of pingroups in @pingroups.
486
- * @pinfuncs: pointer to an array of pin functions this driver manages.
487474 * @pinfuncnt: number of pin functions in @pinfuncs.
488475 * @mutex: mutex for exclusive access to a pin controller's state.
489476 * @ports: current state of each port.
490477 * @gpios: Indicates if a given pin is currently used as GPIO (1) or not (0).
478
+ * @pinfuncs: flexible array of pin functions this driver manages.
491479 */
492480 struct tb10x_pinctrl {
493481 struct pinctrl_dev *pctl;
494482 void *base;
495483 const struct tb10x_pinfuncgrp *pingroups;
496484 unsigned int pinfuncgrpcnt;
497
- struct tb10x_of_pinfunc *pinfuncs;
498485 unsigned int pinfuncnt;
499486 struct mutex mutex;
500487 struct tb10x_port ports[TB10X_PORTS];
501488 DECLARE_BITMAP(gpios, MAX_PIN + 1);
489
+ struct tb10x_of_pinfunc pinfuncs[];
502490 };
503491
504492 static inline void tb10x_pinctrl_set_config(struct tb10x_pinctrl *state,
....@@ -759,7 +747,6 @@
759747 static int tb10x_pinctrl_probe(struct platform_device *pdev)
760748 {
761749 int ret = -EINVAL;
762
- struct resource *mem;
763750 struct device *dev = &pdev->dev;
764751 struct device_node *of_node = dev->of_node;
765752 struct device_node *child;
....@@ -771,19 +758,16 @@
771758 return -EINVAL;
772759 }
773760
774
- state = devm_kzalloc(dev, sizeof(struct tb10x_pinctrl) +
775
- of_get_child_count(of_node)
776
- * sizeof(struct tb10x_of_pinfunc),
777
- GFP_KERNEL);
761
+ state = devm_kzalloc(dev, struct_size(state, pinfuncs,
762
+ of_get_child_count(of_node)),
763
+ GFP_KERNEL);
778764 if (!state)
779765 return -ENOMEM;
780766
781767 platform_set_drvdata(pdev, state);
782
- state->pinfuncs = (struct tb10x_of_pinfunc *)(state + 1);
783768 mutex_init(&state->mutex);
784769
785
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
786
- state->base = devm_ioremap_resource(dev, mem);
770
+ state->base = devm_platform_ioremap_resource(pdev, 0);
787771 if (IS_ERR(state->base)) {
788772 ret = PTR_ERR(state->base);
789773 goto fail;