Remove support for platform data from samsung keypad
Subsystems (8)
Dmitry Torokhov
maintainerv3 cover Remove support for platform data from samsung keypad
Hi,
This series converts the Samsung keypad driver and the Cragganmore 6410 board to generic device properties, allowing the removal of legacy platform data and GPIO lookup tables.
We rework the Samsung keypad driver to stop using platform data, utilizing a new compact matrix keypad binding. To support this on the Cragganmore board, we add infrastructure to associate software nodes with Samsung gpio_chips, and add software node propagation support to the wm831x MFD core to route DVS GPIO to the PMIC regulator.
Finally, we convert all peripherals on the Cragganmore board (including keypad, GPIO keys, PMIC, WM1250, SPI0, basic-mmio-gpio, and LEDs) to software properties. This allows us to eliminate all legacy GPIO lookup tables and fixes incorrect GPIO chip names from previous conversions.
Mark, it would be great if you could give this a spin on Cragganmore.
The majority of changes are in arch/board code, with a couple of input matches and one for MFD. If everyone agrees maybe we can merge it all through the soc tree?
Thanks!
Changes in v3:
- Fixed legacy property handling regression in the keypad driver by separating compact and verbose binding paths
- Removed redundant registration of crag6410_mmgpio_node from mach-crag6410.c
- Removed dead S3C64XX_SETUP_KEYPAD Kconfig symbol definition and selection
- Fixed missing newline in pr_err() message in mach-crag6410.c
- Redesigned PMIC DVS support to keep regulator driver changes minimal (untouched) and only use software nodes for GPIO routing via MFD core
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Patches 1-8 of v1 were merged into mainline, dropping them from this series
- Rebased remaining patches (9-14 of v1) onto latest next
- Resolved conflicts in mach-crag6410.c
- Removed redundant "out of memory" error messages from the keypad driver
- Added an infrastructure patch to register and attach software nodes for Samsung gpio_chips
- Converted basic-mmio-gpio and LEDs on Cragganmore 6410 to software properties in a new separate patch
- Addressed DT bindings feedback on the compact binding patch
- Fixed proximity switch event type for GPIO keys
- Added support for software nodes in wm831x regulator driver
- Converted PMIC DVS on Cragganmore 6410 to software properties using the new driver support
- Removed legacy DVS platform data fields and cleaned up driver fallback.
---
Dmitry Torokhov (10):
dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
Input: samsung-keypad - handle compact binding
ARM: s3c: register and attach software nodes for Samsung gpio_chips
ARM: s3c: crag6410: switch keypad device to software properties
Input: samsung-keypad - remove support for platform data
ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys
mfd: wm831x: support software nodes for DCDC regulators
ARM: s3c: crag6410: convert PMIC DVS GPIO to software properties
ARM: s3c: crag6410: convert basic-mmio-gpio and LEDs to software properties
ARM: s3c: crag6410: convert remaining GPIO lookup tables to property entries
.../bindings/input/samsung,s3c6410-keypad.yaml | 53 ++- arch/arm/mach-s3c/Kconfig | 5 - arch/arm/mach-s3c/Kconfig.s3c64xx | 7 - arch/arm/mach-s3c/Makefile.s3c64xx | 1 - arch/arm/mach-s3c/devs.c | 62 ---- arch/arm/mach-s3c/devs.h | 2 - arch/arm/mach-s3c/gpio-core.h | 3 + arch/arm/mach-s3c/gpio-samsung-s3c64xx.h | 5 + arch/arm/mach-s3c/gpio-samsung.c | 72 +++- arch/arm/mach-s3c/keypad.h | 27 -- arch/arm/mach-s3c/mach-crag6410.c | 369 +++++++++++++-------- arch/arm/mach-s3c/setup-keypad-s3c64xx.c | 20 -- drivers/input/keyboard/samsung-keypad.c | 200 +++++------ drivers/mfd/wm831x-core.c | 47 ++- include/linux/input/samsung-keypad.h | 39 --- include/linux/mfd/wm831x/pdata.h | 2 + 16 files changed, 472 insertions(+), 442 deletions(-)
---
base-commit: 8e9685d3c41c35dd1b37df70d854137abcb2fbac
change-id: 20240819-samsung-kp-ceedd4f2f720
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerPATCH v3 1/10 dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
The binding with a sub-node per each key is very verbose and is hard to use with static device properties. Allow standard matrix keymap binding in addition to the verbose one.
--- .../bindings/input/samsung,s3c6410-keypad.yaml | 53 ++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +50 -3
@@ -37,6 +37,10 @@ properties: wakeup-source: true + keypad,num-columns: true + keypad,num-rows: true + linux,keymap: true + linux,input-no-autorepeat: type: boolean description:
@@ -81,12 +85,33 @@ patternProperties: - keypad,row - linux,code +dependencies: + linux,keymap: [ "keypad,num-columns", "keypad,num-rows" ] + required: - compatible - reg - interrupts - - samsung,keypad-num-columns - - samsung,keypad-num-rows + +allOf: + - $ref: input.yaml# + - $ref: matrix-keymap.yaml# + - if: + required: + - linux,keymap + then: + properties: + samsung,keypad-num-columns: false + samsung,keypad-num-rows: false + patternProperties: + '^key-[0-9a-z]+$': false + else: + properties: + keypad,num-columns: false + keypad,num-rows: false + required: + - samsung,keypad-num-columns + - samsung,keypad-num-rows additionalProperties: false
@@ -94,8 +119,9 @@ examples: - | #include <dt-bindings/clock/exynos4.h> #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/input/input.h> - keypad@100a0000 { + keypad1@100a0000 { compatible = "samsung,s5pv210-keypad"; reg = <0x100a0000 0x100>; interrupts = <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
@@ -119,3 +145,24 @@ examples: linux,code = <3>; }; }; + - | + #include <dt-bindings/clock/exynos4.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/input/input.h> + + keypad2@100a0000 { + compatible = "samsung,s5pv210-keypad"; + reg = <0x100a0000 0x100>; + interrupts = <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clock CLK_KEYIF>; + clock-names = "keypad"; + + keypad,num-rows = <2>; + keypad,num-columns = <8>; + linux,keymap = < + MATRIX_KEY(0, 3, 2) + MATRIX_KEY(0, 4, 3) + >; + linux,input-no-autorepeat; + wakeup-source; + };
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 01/10] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly introduced compact DT binding is completely unsupported by the driver, leading to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly introduced compact DT binding is completely unsupported by the driver, leading to guaranteed probe failure. --
--- Patch [1]: [PATCH v3 01/10] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding --- commit c3ae19e70e1090e5ebc5290a0659633378fd46d7
Author: Dmitry Torokhov <[email protected]>
dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
This commit updates the samsung,s3c6410-keypad devicetree binding to support the standard matrix keymap binding. It makes the legacy samsung,keypad-num-columns and samsung,keypad-num-rows properties mutually exclusive with the standard linux,keymap property.
Quoted 3 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +0
-0
[ ... ]
Quoted 14 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +4
-2@@ -81,12 +85,33 @@ patternProperties: - keypad,row - linux,code +dependencies: + linux,keymap: [ "keypad,num-columns", "keypad,num-rows" ] + required: - compatible - reg - interrupts - - samsung,keypad-num-columns - - samsung,keypad-num-rows +
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 105
Quoted 10 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +10
-0+allOf: + - $ref: input.yaml# + - $ref: matrix-keymap.yaml# + - if: + required: + - linux,keymap + then: + properties: + samsung,keypad-num-columns: false + samsung,keypad-num-rows: false
[Severity: Medium]
Will device trees using this new compact binding fail to probe?
The new binding explicitly forbids the samsung,keypad-num-columns and samsung,keypad-num-rows properties when linux,keymap is used. However, the current driver code in drivers/input/keyboard/samsung-keypad.c unconditionally requires them:
drivers/input/keyboard/samsung-keypad.c:samsung_keypad_parse_dt() {
...
of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows);
of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols);
if (!num_rows || !num_cols) {
dev_err(dev, "number of keypad rows/columns not specified\n");
return ERR_PTR(-EINVAL);
}
...
}This means a device tree written with the new compact binding format will cause the keypad hardware probe to fail immediately with -EINVAL.
Additionally, if that check were bypassed, does the driver's current keymap initialization conflict with the standard matrix keypad parsing?
drivers/input/keyboard/samsung-keypad.c:samsung_keypad_probe() {
...
error = matrix_keypad_build_keymap(keymap_data, NULL,
pdata->rows, pdata->cols,
keypad->keycodes, input_dev);
...
}Because samsung_keypad_parse_dt() currently unconditionally allocates an empty keymap_data structure, passing a non-null pointer here prevents matrix_keypad_build_keymap() from falling back to parsing the linux,keymap property directly from the device tree.
Are there corresponding driver updates planned to support these new properties alongside this binding change?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Dmitry Torokhov
maintainerPATCH v3 2/10 Input: samsung-keypad - handle compact binding
In reply to Dmitry TorokhovAdd support for standard matrix keymap binding (in addition to the existing verbose binding with a sub-node for each key). This will allow easier conversions from platform data to device properties when using static device properties.
--- drivers/input/keyboard/samsung-keypad.c | 134 +++++++++++++++++--------------- 1 file changed, 71 insertions(+), 63 deletions(-)
drivers/input/keyboard/samsung-keypad.c +71 -63
@@ -231,83 +231,89 @@ static void samsung_keypad_close(struct input_dev *input_dev)samsung_keypad_stop (keypad); } -#ifdef CONFIG_OF -static struct samsung_keypad_platdata * -samsung_keypad_parse_dt (struct device *dev) +static const struct matrix_keymap_data * +samsung_parse_verbose_keymap (struct device *dev) { -struct samsung_keypad_platdata *pdata;struct matrix_keymap_data *keymap_data; -uint32_t *keymap, num_rows =0 , num_cols =0 ; -struct device_node *np = dev->of_node, *key_np; +struct fwnode_handle *child; +u32 *keymap;unsigned int key_count; -if (!np) { -dev_err (dev,"missing device tree data\n" ); -return ERR_PTR (-EINVAL ); + keymap_data =devm_kzalloc (dev,sizeof (*keymap_data),GFP_KERNEL ); +if (!keymap_data) +return ERR_PTR (-ENOMEM ); + + key_count =device_get_child_node_count (dev); + keymap =devm_kcalloc (dev, key_count,sizeof (*keymap),GFP_KERNEL ); +if (!keymap) +return ERR_PTR (-ENOMEM ); + + keymap_data->keymap_size = key_count; + keymap_data->keymap = keymap; + +device_for_each_child_node (dev, child) { +u32 row, col, key_code; + +fwnode_property_read_u32 (child,"keypad,row" , &row); +fwnode_property_read_u32 (child,"keypad,column" , &col); +fwnode_property_read_u32 (child,"linux,code" , &key_code); + + *keymap++ =KEY (row, col, key_code); } +return keymap_data; +} + +static const struct samsung_keypad_platdata * +samsung_keypad_parse_properties (struct device *dev) +{ +const struct matrix_keymap_data *keymap_data; +struct samsung_keypad_platdata *pdata; +u32 num_rows =0 , num_cols =0 ; +int error; + pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) { -dev_err (dev,"could not allocate memory for platform data\n" ); +if (!pdata)return ERR_PTR (-ENOMEM ); - } -of_property_read_u32 (np,"samsung,keypad-num-rows" , &num_rows); -of_property_read_u32 (np,"samsung,keypad-num-columns" , &num_cols); -if (!num_rows || !num_cols) { -dev_err (dev,"number of keypad rows/columns not specified\n" ); -return ERR_PTR (-EINVAL ); +if (device_property_present (dev,"linux,keymap" )) { + error =matrix_keypad_parse_properties (dev, &num_rows, &num_cols); +if (error) +return ERR_PTR (error); + }else { +device_property_read_u32 (dev,"samsung,keypad-num-rows" , &num_rows); +device_property_read_u32 (dev,"samsung,keypad-num-columns" , &num_cols); +if (!num_rows || !num_cols) { +dev_err (dev,"number of keypad rows/columns not specified\n" ); +return ERR_PTR (-EINVAL ); + } } + pdata->rows = num_rows; pdata->cols = num_cols; - keymap_data =devm_kzalloc (dev,sizeof (*keymap_data),GFP_KERNEL ); -if (!keymap_data) { -dev_err (dev,"could not allocate memory for keymap data\n" ); -return ERR_PTR (-ENOMEM ); - } - pdata->keymap_data = keymap_data; +if (!device_property_present (dev,"linux,keymap" )) { + keymap_data =samsung_parse_verbose_keymap (dev); +if (IS_ERR (keymap_data)) +return ERR_CAST (keymap_data); - key_count =of_get_child_count (np); - keymap_data->keymap_size = key_count; - keymap =devm_kcalloc (dev, key_count,sizeof (uint32_t ),GFP_KERNEL ); -if (!keymap) { -dev_err (dev,"could not allocate memory for keymap\n" ); -return ERR_PTR (-ENOMEM ); + pdata->keymap_data = keymap_data; } - keymap_data->keymap = keymap; -for_each_child_of_node (np, key_np) { -u32 row, col, key_code; -of_property_read_u32 (key_np,"keypad,row" , &row); -of_property_read_u32 (key_np,"keypad,column" , &col); -of_property_read_u32 (key_np,"linux,code" , &key_code); - *keymap++ =KEY (row, col, key_code); - } - pdata->no_autorepeat =of_property_read_bool (np,"linux,input-no-autorepeat" ); + pdata->no_autorepeat = +device_property_read_bool (dev,"linux,input-no-autorepeat" ); - pdata->wakeup =of_property_read_bool (np,"wakeup-source" ) || + pdata->wakeup =device_property_read_bool (dev,"wakeup-source" ) ||/* legacy name */ -of_property_read_bool (np,"linux,input-wakeup" ); - +device_property_read_bool (dev,"linux,input-wakeup" );return pdata; } -#else -static struct samsung_keypad_platdata * -samsung_keypad_parse_dt (struct device *dev) -{ -dev_err (dev,"no platform data defined\n" ); - -return ERR_PTR (-EINVAL ); -} -#endif static int samsung_keypad_probe (struct platform_device *pdev) {const struct samsung_keypad_platdata *pdata; -const struct matrix_keymap_data *keymap_data;const struct platform_device_id *id;struct samsung_keypad *keypad;struct resource *res;
@@ -316,18 +322,17 @@ static int samsung_keypad_probe(struct platform_device *pdev)int error; pdata =dev_get_platdata (&pdev->dev); -if (!pdata) { - pdata =samsung_keypad_parse_dt (&pdev->dev); +if (pdata) { +if (!pdata->keymap_data) { +dev_err (&pdev->dev,"no keymap data defined\n" ); +return -EINVAL ; + } + }else { + pdata =samsung_keypad_parse_properties (&pdev->dev);if (IS_ERR (pdata))return PTR_ERR (pdata); } - keymap_data = pdata->keymap_data; -if (!keymap_data) { -dev_err (&pdev->dev,"no keymap data defined\n" ); -return -EINVAL ; - } -if (!pdata->rows || pdata->rows >SAMSUNG_MAX_ROWS )return -EINVAL ;
@@ -391,7 +396,7 @@ static int samsung_keypad_probe(struct platform_device *pdev) input_dev->open = samsung_keypad_open; input_dev->close = samsung_keypad_close; - error =matrix_keypad_build_keymap (keymap_data,NULL , + error =matrix_keypad_build_keymap (pdata->keymap_data,NULL , pdata->rows, pdata->cols, keypad->keycodes, input_dev);if (error) {
@@ -430,11 +435,14 @@ static int samsung_keypad_probe(struct platform_device *pdev)if (error)return error; -if (pdev->dev.of_node) { -devm_kfree (&pdev->dev, (void *)pdata->keymap_data->keymap); -devm_kfree (&pdev->dev, (void *)pdata->keymap_data); +if (!dev_get_platdata (&pdev->dev)) { +if (pdata->keymap_data) { +devm_kfree (&pdev->dev, (void *)pdata->keymap_data->keymap); +devm_kfree (&pdev->dev, (void *)pdata->keymap_data); + }devm_kfree (&pdev->dev, (void *)pdata); } +return 0 ; }
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 02/10] Input: samsung-keypad - handle compact binding
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] IRQ handler is requested before runtime PM is enabled, leading to potential bus faults.
- [High] Uninitialized stack variables row, col, and key_code leak kernel stack memory and can cause out-of-bounds array access.
- [Medium] Time-of-Check to Time-of-Use (TOCTOU) race condition when parsing child nodes causes heap buffer overflow. --
--- Patch [2]: [PATCH v3 02/10] Input: samsung-keypad - handle compact binding --- commit df7d9c0ab9ce4671eb0b2980bb819cb1ac325753
Author: Dmitry Torokhov <[email protected]>
Subject: Input: samsung-keypad - handle compact binding
Add support for standard matrix keymap binding (in addition to the existing verbose binding with a sub-node for each key). This will allow easier conversions from platform data to device properties when using static device properties.
Quoted 11 lines
drivers/input/keyboard/samsung-keypad.c +0
-3@@ -231,83 +231,89 @@ static void samsung_keypad_close(struct input_dev *input_dev)samsung_keypad_stop (keypad); } -#ifdef CONFIG_OF -static struct samsung_keypad_platdata * -samsung_keypad_parse_dt (struct device *dev)
[ ... ]
Quoted 18 lines
drivers/input/keyboard/samsung-keypad.c +18
-0+static const struct matrix_keymap_data * +samsung_parse_verbose_keymap (struct device *dev) +{ +struct matrix_keymap_data *keymap_data; +struct fwnode_handle *child; +u32 *keymap; +unsigned int key_count; + + keymap_data =devm_kzalloc (dev,sizeof (*keymap_data),GFP_KERNEL ); +if (!keymap_data) +return ERR_PTR (-ENOMEM ); + + key_count =device_get_child_node_count (dev); + keymap =devm_kcalloc (dev, key_count,sizeof (*keymap),GFP_KERNEL ); +if (!keymap) +return ERR_PTR (-ENOMEM ); + + keymap_data->keymap_size = key_count;
drivers/input/keyboard/samsung-keypad.c
Quoted 10 lines
drivers/input/keyboard/samsung-keypad.c +10
-0+ keymap_data->keymap = keymap; + +device_for_each_child_node (dev, child) { +u32 row, col, key_code; + +fwnode_property_read_u32 (child,"keypad,row" , &row); +fwnode_property_read_u32 (child,"keypad,column" , &col); +fwnode_property_read_u32 (child,"linux,code" , &key_code); + + *keymap++ =KEY (row, col, key_code);
[Severity: Medium]
This is a pre-existing issue, but could this loop overflow the allocated keymap array?
The array size is determined earlier:
key_count = device_get_child_node_count(dev); keymap = devm_kcalloc(dev, key_count, sizeof(*keymap), GFP_KERNEL);
Because there is no synchronization explicitly held, if a concurrent device tree overlay adds a child node to the keypad between the count and the iteration here in device_for_each_child_node(), could the loop execute more times than allocated and cause an out-of-bounds heap write?
[Severity: High]
This isn't a bug introduced by this patch, but what happens if the device tree child node is missing properties?
If fwnode_property_read_u32() fails for "keypad,row", "keypad,column", or "linux,code", it leaves the output variables uninitialized.
Since the return values are ignored, the uninitialized stack variables row, col, and key_code are passed into the KEY() macro and written to the keymap. Could this leak kernel stack memory to userspace via the EVIOCGKEYCODE ioctl, or create incorrect key mappings?
Quoted 4 lines
drivers/input/keyboard/samsung-keypad.c +2
-0} +return keymap_data; +}
[ ... ]
Quoted 5 lines
drivers/input/keyboard/samsung-keypad.c +0
-1@@ -430,11 +435,14 @@ static int samsung_keypad_probe(struct platform_device *pdev)if (error)return error; -if (pdev->dev.of_node) {
drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 445
Quoted 10 lines
drivers/input/keyboard/samsung-keypad.c +6
-2-devm_kfree (&pdev->dev, (void *)pdata->keymap_data->keymap); -devm_kfree (&pdev->dev, (void *)pdata->keymap_data); +if (!dev_get_platdata (&pdev->dev)) { +if (pdata->keymap_data) { +devm_kfree (&pdev->dev, (void *)pdata->keymap_data->keymap); +devm_kfree (&pdev->dev, (void *)pdata->keymap_data); + }devm_kfree (&pdev->dev, (void *)pdata); } +
[Severity: High]
This is a pre-existing issue, but could the IRQ handler run before runtime PM is enabled?
In samsung_keypad_probe(), devm_request_threaded_irq() is called to unmask the IRQ before devm_pm_runtime_enable() is called:
error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, samsung_keypad_irq, IRQF_ONESHOT, dev_name(&pdev->dev), keypad); [ ... ] error = devm_pm_runtime_enable(&pdev->dev);
If an interrupt is pending (for example, left over from the bootloader), samsung_keypad_irq() could fire immediately. The handler calls pm_runtime_get_sync(), which would return -EACCES because runtime PM is not yet enabled.
If the handler then reads from keypad->base with a disabled clock, could this cause a bus fault?
Quoted 2 lines
drivers/input/keyboard/samsung-keypad.c +0
-0return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Dmitry Torokhov
maintainerPATCH v3 3/10 ARM: s3c: register and attach software nodes for Samsung gpio_chips
In reply to Dmitry TorokhovDefine and register software nodes for the Samsung GPIO chips on legacy (non-DT) platforms.
Attach the matching software node to each gpio_chip's fwnode during registration, using the bank label to calculate the index.
This provides the infrastructure for converting board files and drivers to use software nodes/properties instead of legacy platform data or GPIO lookup tables.
--- arch/arm/mach-s3c/gpio-core.h | 3 ++ arch/arm/mach-s3c/gpio-samsung-s3c64xx.h | 5 +++ arch/arm/mach-s3c/gpio-samsung.c | 72 ++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 17 deletions(-)
arch/arm/mach-s3c/gpio-core.h +3 -0
@@ -14,6 +14,8 @@#include "gpio-samsung.h" #include <linux/gpio/driver.h> +struct software_node ; +#define GPIOCON_OFF (0x00)#define GPIODAT_OFF (0x04)
@@ -66,6 +68,7 @@ struct samsung_gpio_cfg;*/ struct samsung_gpio_chip {struct gpio_chip chip; +const struct software_node *swnode;struct samsung_gpio_cfg *config;struct samsung_gpio_pm *pm;void __iomem *base;
arch/arm/mach-s3c/gpio-samsung-s3c64xx.h +5 -0
@@ -13,6 +13,8 @@#ifdef CONFIG_GPIO_SAMSUNG +#include <linux/property.h> +/* GPIO bank sizes */ #define S3C64XX_GPIO_A_NR (8)#define S3C64XX_GPIO_B_NR (7)
@@ -89,6 +91,9 @@ enum s3c_gpio_number {/* define the number of gpios we need to the one after the GPQ() range */ #define GPIO_BOARD_START (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1) +extern const struct software_node samsung_gpiochip_nodes[]; +#define SAMSUNG_GPIO_NODE (node) (&samsung_gpiochip_nodes[(node) - 'A']) +#endif /* GPIO_SAMSUNG */ #endif /* GPIO_SAMSUNG_S3C64XX_H */
arch/arm/mach-s3c/gpio-samsung.c +55 -17
211 lines not on this page · raw message
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 03/10] ARM: s3c: register and attach software nodes for Samsung gpio_chips
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The 4-bit and 4-bit2 GPIO direction configuration functions perform read-modify-write operations on shared configuration registers without holding the chip's spinlock, leading to race conditions. --
--- Patch [3]: [PATCH v3 03/10] ARM: s3c: register and attach software nodes for Samsung gpio_chips --- commit 8053fb79cb15e3c5c2e66691008b5adc30b3e152
Author: Dmitry Torokhov <[email protected]>
ARM: s3c: register and attach software nodes for Samsung gpio_chips
This commit defines and registers software nodes for the Samsung GPIO chips on legacy platforms. It attaches the matching software node to each gpio_chip's fwnode during registration, providing the infrastructure to convert board files and drivers to use software nodes instead of legacy platform data.
Quoted 3 lines
arch/arm/mach-s3c/gpio-samsung.c +0
-0
[ ... ]
arch/arm/mach-s3c/gpio-samsung.c static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = { · line 699
Quoted 7 lines
arch/arm/mach-s3c/gpio-samsung.c +1
-1@@ -659,49 +695,49 @@ static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = { .chip = { .base = S3C64XX_GPA(0), .ngpio = S3C64XX_GPIO_A_NR, - .label = "GPA", }, + .swnode = SAMSUNG_GPIO_NODE('A'),
[Severity: High]
This is a pre-existing issue, but since we are updating the 4-bit GPIO chip registrations here, should the underlying 4-bit configuration functions be updated to use the chip->lock?
Currently, functions like samsung_gpiolib_4bit_input() perform read-modify-write operations on shared configuration registers without locking:
samsung_gpiolib_4bit_input() {
...
con = __raw_readl(base + GPIOCON_OFF);
if (ourchip->bitmap_gpio_int & BIT(offset))
con |= 0xf << con_4bit_shift(offset);
else
con &= ~(0xf << con_4bit_shift(offset));
__raw_writel(con, base + GPIOCON_OFF);
...
}Similar unprotected read-modify-write sequences exist in samsung_gpiolib_4bit_output() (for both GPIOCON and GPIODAT) and samsung_gpiolib_4bit2_input().
If two threads concurrently attempt to change the direction of different GPIO pins in the same bank, could this lead to lost or corrupted configuration updates?
Quoted 1 line
arch/arm/mach-s3c/gpio-samsung.c +0
-0}, {
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Dmitry Torokhov
maintainerPATCH v3 4/10 ARM: s3c: crag6410: switch keypad device to software properties
In reply to Dmitry TorokhovSwitch the keypad device to use software properties to describe the keypad. This will allow dropping support for platform data from the samsung-keypad driver.
--- arch/arm/mach-s3c/Kconfig | 5 --- arch/arm/mach-s3c/Kconfig.s3c64xx | 7 ---- arch/arm/mach-s3c/Makefile.s3c64xx | 1 - arch/arm/mach-s3c/devs.c | 27 --------------- arch/arm/mach-s3c/devs.h | 1 - arch/arm/mach-s3c/keypad.h | 27 --------------- arch/arm/mach-s3c/mach-crag6410.c | 56 ++++++++++++++++++++++++-------- arch/arm/mach-s3c/setup-keypad-s3c64xx.c | 20 ------------ 8 files changed, 42 insertions(+), 102 deletions(-)
arch/arm/mach-s3c/Kconfig +0 -5
@@ -111,11 +111,6 @@ config S3C64XX_DEV_SPI0 Compile in platform device definitions for S3C64XX's type SPI controller 0 -config SAMSUNG_DEV_KEYPAD - bool - help - Compile in platform device definitions for keypad - config SAMSUNG_DEV_PWM bool help
arch/arm/mach-s3c/Kconfig.s3c64xx +0 -7
@@ -74,11 +74,6 @@ config S3C64XX_SETUP_FB_24BPP help Common setup code for S3C64XX with an 24bpp RGB display helper. -config S3C64XX_SETUP_KEYPAD - bool - help - Common setup code for S3C64XX KEYPAD GPIO configurations - config S3C64XX_SETUP_SDHCI_GPIO bool help
@@ -106,7 +101,6 @@ config MACH_WLF_CRAGG_6410 select S3C64XX_DEV_SPI0 select S3C64XX_SETUP_FB_24BPP select S3C64XX_SETUP_I2C1 - select S3C64XX_SETUP_KEYPAD select S3C64XX_SETUP_SDHCI select S3C64XX_SETUP_SPI select S3C64XX_SETUP_USB_PHY
@@ -117,7 +111,6 @@ config MACH_WLF_CRAGG_6410 select S3C_DEV_I2C1 select S3C_DEV_USB_HOST select S3C_DEV_USB_HSOTG - select SAMSUNG_DEV_KEYPAD select SAMSUNG_DEV_PWM help Machine support for the Wolfson Cragganmore S3C6410 variant.
arch/arm/mach-s3c/Makefile.s3c64xx +0 -1
@@ -32,7 +32,6 @@ obj-y += dev-audio-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_FB_24BPP) += setup-fb-24bpp-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_I2C0) += setup-i2c0-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_I2C1) += setup-i2c1-s3c64xx.o -obj-$(CONFIG_S3C64XX_SETUP_KEYPAD) += setup-keypad-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_SDHCI_GPIO) += setup-sdhci-gpio-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_SPI) += setup-spi-s3c64xx.o obj-$(CONFIG_S3C64XX_SETUP_USB_PHY) += setup-usb-phy-s3c64xx.o
arch/arm/mach-s3c/devs.c +0 -27
@@ -39,7 +39,6 @@#include "devs.h" #include "fb.h" #include <linux/platform_data/i2c-s3c2410.h> -#include "keypad.h" #include "pwm-core.h" #include "sdhci.h" #include "usb-phy.h"
@@ -265,32 +264,6 @@ void __init s3c_i2c1_set_platdata(struct s3c2410_platform_i2c *pd) }#endif /* CONFIG_S3C_DEV_I2C1 */ -/* KEYPAD */ - -#ifdef CONFIG_SAMSUNG_DEV_KEYPAD -static struct resource samsung_keypad_resources[] = { - [0 ] =DEFINE_RES_MEM (SAMSUNG_PA_KEYPAD ,SZ_32 ), - [1 ] =DEFINE_RES_IRQ (IRQ_KEYPAD ), -}; - -struct platform_device samsung_device_keypad = { - .name ="samsung-keypad" , - .id =-1 , - .num_resources =ARRAY_SIZE (samsung_keypad_resources), - .resource = samsung_keypad_resources, -}; - -void __init samsung_keypad_set_platdata (struct samsung_keypad_platdata *pd) -{ -struct samsung_keypad_platdata *npd; - - npd =s3c_set_platdata (pd,sizeof (*npd), &samsung_device_keypad); - -if (!npd->cfg_gpio) - npd->cfg_gpio = samsung_keypad_cfg_gpio; -} -#endif /* CONFIG_SAMSUNG_DEV_KEYPAD */ -/* PWM Timer */ #ifdef CONFIG_SAMSUNG_DEV_PWM
arch/arm/mach-s3c/devs.h +0 -1
@@ -39,7 +39,6 @@ extern struct platform_device s3c_device_i2c1;extern struct platform_device s3c_device_ohci;extern struct platform_device s3c_device_usb_hsotg; -extern struct platform_device samsung_device_keypad;extern struct platform_device samsung_device_pwm;/**
arch/arm/mach-s3c/keypad.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* -* Samsung Platform - Keypad platform data definitions -* -* Copyright (C) 2010 Samsung Electronics Co.Ltd -* Author: Joonyoung Shim <[email protected]> -*/ - -#ifndef __PLAT_SAMSUNG_KEYPAD_H -#define __PLAT_SAMSUNG_KEYPAD_H - -#include <linux/input/samsung-keypad.h> - -/** -* samsung_keypad_set_platdata - Set platform data for Samsung Keypad device. -* @pd: Platform data to register to device. -* -* Register the given platform data for use with Samsung Keypad device. -* The call will copy the platform data, so the board definitions can -* make the structure itself __initdata. -*/ -extern void samsung_keypad_set_platdata (struct samsung_keypad_platdata *pd); - -/* defined by architecture to configure gpio. */ -extern void samsung_keypad_cfg_gpio (unsigned int rows,unsigned int cols); - -#endif /* __PLAT_SAMSUNG_KEYPAD_H */
arch/arm/mach-s3c/mach-crag6410.c +42 -14
116 lines not on this page · raw message
arch/arm/mach-s3c/setup-keypad-s3c64xx.c deleted +0 -20
@@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -// -// Copyright (c) 2010 Samsung Electronics Co., Ltd. -// http://www.samsung.com/ -// -// GPIO configuration for S3C64XX KeyPad device - -#include <linux/gpio.h> -#include "gpio-cfg.h" -#include "keypad.h" -#include "gpio-samsung.h" - -void samsung_keypad_cfg_gpio (unsigned int rows,unsigned int cols) -{ -/* Set all the necessary GPK pins to special-function 3: KP_ROW[x] */ -s3c_gpio_cfgrange_nopull (S3C64XX_GPK (8 ), rows,S3C_GPIO_SFN (3 )); - -/* Set all the necessary GPL pins to special-function 3: KP_COL[x] */ -s3c_gpio_cfgrange_nopull (S3C64XX_GPL (0 ), cols,S3C_GPIO_SFN (3 )); -}
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Dmitry Torokhov
maintainerPATCH v3 5/10 Input: samsung-keypad - remove support for platform data
In reply to Dmitry TorokhovBecause there are no more users of samsung_keypad_platdata left in the kernel remove support for it from the driver.
The driver supports generic device properties so all configuration should be done using them instead of a custom platform data.
--- drivers/input/keyboard/samsung-keypad.c | 184 +++++++++++++------------------- include/linux/input/samsung-keypad.h | 39 ------- 2 files changed, 72 insertions(+), 151 deletions(-)
drivers/input/keyboard/samsung-keypad.c +72 -112
@@ -12,6 +12,7 @@#include <linux/delay.h> #include <linux/err.h> #include <linux/input.h> +#include <linux/input/matrix_keypad.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h>
@@ -21,7 +22,9 @@#include <linux/slab.h> #include <linux/of.h> #include <linux/sched.h> -#include <linux/input/samsung-keypad.h> + +#define SAMSUNG_MAX_ROWS 8 +#define SAMSUNG_MAX_COLS 8#define SAMSUNG_KEYIFCON 0x00#define SAMSUNG_KEYIFSTSCLR 0x04
@@ -231,26 +234,22 @@ static void samsung_keypad_close(struct input_dev *input_dev)samsung_keypad_stop (keypad); } -static const struct matrix_keymap_data * -samsung_parse_verbose_keymap (struct device *dev) +static int samsung_parse_verbose_keymap (struct samsung_keypad *keypad) { -struct matrix_keymap_data *keymap_data; +struct matrix_keymap_data keymap_data = {0 }; +struct device *dev = &keypad->pdev->dev;struct fwnode_handle *child; -u32 *keymap; -unsigned int key_count; - - keymap_data =devm_kzalloc (dev,sizeof (*keymap_data),GFP_KERNEL ); -if (!keymap_data) -return ERR_PTR (-ENOMEM ); +unsigned int key_count =device_get_child_node_count (dev); +unsigned int i; - key_count =device_get_child_node_count (dev); - keymap =devm_kcalloc (dev, key_count,sizeof (*keymap),GFP_KERNEL ); + u32 *keymap __free(kfree) = kcalloc(key_count, sizeof(*keymap), GFP_KERNEL);if (!keymap) -return ERR_PTR (-ENOMEM ); +return -ENOMEM ; - keymap_data->keymap_size = key_count; - keymap_data->keymap = keymap; + keymap_data.keymap_size = key_count; + keymap_data.keymap = keymap; + i =0 ;device_for_each_child_node (dev, child) {u32 row, col, key_code;
@@ -258,123 +257,69 @@ samsung_parse_verbose_keymap(struct device *dev)fwnode_property_read_u32 (child,"keypad,column" , &col);fwnode_property_read_u32 (child,"linux,code" , &key_code); - *keymap++ =KEY (row, col, key_code); + keymap[i++] =KEY (row, col, key_code); } -return keymap_data; +return matrix_keypad_build_keymap (&keymap_data,NULL , + keypad->rows, keypad->cols, + keypad->keycodes, + keypad->input_dev); } -static const struct samsung_keypad_platdata * -samsung_keypad_parse_properties (struct device *dev) +static int samsung_keypad_parse_keymap (struct samsung_keypad *keypad) { -const struct matrix_keymap_data *keymap_data; -struct samsung_keypad_platdata *pdata; -u32 num_rows =0 , num_cols =0 ; -int error; - - pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) -return ERR_PTR (-ENOMEM ); - -if (device_property_present (dev,"linux,keymap" )) { - error =matrix_keypad_parse_properties (dev, &num_rows, &num_cols); -if (error) -return ERR_PTR (error); - }else { -device_property_read_u32 (dev,"samsung,keypad-num-rows" , &num_rows); -device_property_read_u32 (dev,"samsung,keypad-num-columns" , &num_cols); -if (!num_rows || !num_cols) { -dev_err (dev,"number of keypad rows/columns not specified\n" ); -return ERR_PTR (-EINVAL ); - } - } - - pdata->rows = num_rows; - pdata->cols = num_cols; - -if (!device_property_present (dev,"linux,keymap" )) { - keymap_data =samsung_parse_verbose_keymap (dev); -if (IS_ERR (keymap_data)) -return ERR_CAST (keymap_data); - - pdata->keymap_data = keymap_data; - } - - - pdata->no_autorepeat = -device_property_read_bool (dev,"linux,input-no-autorepeat" ); +struct device *dev = &keypad->pdev->dev; - pdata->wakeup =device_property_read_bool (dev,"wakeup-source" ) || -/* legacy name */ -device_property_read_bool (dev,"linux,input-wakeup" ); +if (device_property_present (dev,"linux,keymap" )) +return matrix_keypad_build_keymap (NULL ,NULL , + keypad->rows, keypad->cols, + keypad->keycodes, + keypad->input_dev); -return pdata; +return samsung_parse_verbose_keymap (keypad); }static int samsung_keypad_probe (struct platform_device *pdev) { -const struct samsung_keypad_platdata *pdata;const struct platform_device_id *id; +struct device *dev = &pdev->dev;struct samsung_keypad *keypad;struct resource *res;struct input_dev *input_dev;unsigned int row_shift; +u32 num_rows =0 , num_cols =0 ; +bool wakeup;int error; - pdata =dev_get_platdata (&pdev->dev); -if (pdata) { -if (!pdata->keymap_data) { -dev_err (&pdev->dev,"no keymap data defined\n" ); +if (device_property_present (dev,"linux,keymap" )) { + error =matrix_keypad_parse_properties (dev, &num_rows, &num_cols); +if (error) +return error; + }else { +device_property_read_u32 (dev,"samsung,keypad-num-rows" , &num_rows); +device_property_read_u32 (dev,"samsung,keypad-num-columns" , &num_cols); +if (!num_rows || !num_cols) { +dev_err (dev,"number of keypad rows/columns not specified\n" );return -EINVAL ; } - }else { - pdata =samsung_keypad_parse_properties (&pdev->dev); -if (IS_ERR (pdata)) -return PTR_ERR (pdata); } -if (!pdata->rows || pdata->rows >SAMSUNG_MAX_ROWS ) -return -EINVAL ; - -if (!pdata->cols || pdata->cols >SAMSUNG_MAX_COLS ) +if (num_rows >SAMSUNG_MAX_ROWS || num_cols >SAMSUNG_MAX_COLS )return -EINVAL ; -/* initialize the gpio */ -if (pdata->cfg_gpio) - pdata->cfg_gpio (pdata->rows, pdata->cols); - - row_shift =get_count_order (pdata->cols); + row_shift =get_count_order (num_cols); keypad =devm_kzalloc (&pdev->dev,struct_size (keypad, keycodes, - pdata->rows << row_shift), + num_rows << row_shift),GFP_KERNEL );if (!keypad)return -ENOMEM ; - input_dev =devm_input_allocate_device (&pdev->dev); -if (!input_dev) -return -ENOMEM ; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) -return -ENODEV ; - - keypad->base =devm_ioremap (&pdev->dev, res->start,resource_size (res)); -if (!keypad->base) -return -EBUSY ; - - keypad->clk =devm_clk_get_prepared (&pdev->dev,"keypad" ); -if (IS_ERR (keypad->clk)) { -dev_err (&pdev->dev,"failed to get keypad clk\n" ); -return PTR_ERR (keypad->clk); - } - - keypad->input_dev = input_dev; keypad->pdev = pdev; keypad->row_shift = row_shift; - keypad->rows = pdata->rows; - keypad->cols = pdata->cols; + keypad->rows = num_rows; + keypad->cols = num_cols; keypad->stopped = true;init_waitqueue_head (&keypad->wait);
@@ -390,26 +335,45 @@ static int samsung_keypad_probe(struct platform_device *pdev)return -EINVAL ; } + input_dev =devm_input_allocate_device (&pdev->dev); +if (!input_dev) +return -ENOMEM ; + + keypad->input_dev = input_dev; + input_dev->name = pdev->name; input_dev->id.bustype =BUS_HOST ; input_dev->open = samsung_keypad_open; input_dev->close = samsung_keypad_close; - error =matrix_keypad_build_keymap (pdata->keymap_data,NULL , - pdata->rows, pdata->cols, - keypad->keycodes, input_dev); + error =samsung_keypad_parse_keymap (keypad);if (error) {dev_err (&pdev->dev,"failed to build keymap\n" );return error; }input_set_capability (input_dev,EV_MSC ,MSC_SCAN ); -if (!pdata->no_autorepeat) + +if (!device_property_read_bool (&pdev->dev,"linux,input-no-autorepeat" ))__set_bit (EV_REP , input_dev->evbit);input_set_drvdata (input_dev, keypad); + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -ENODEV ; + + keypad->base =devm_ioremap (&pdev->dev, res->start,resource_size (res)); +if (!keypad->base) +return -EBUSY ; + + keypad->clk =devm_clk_get_prepared (&pdev->dev,"keypad" ); +if (IS_ERR (keypad->clk)) { +dev_err (&pdev->dev,"failed to get keypad clk\n" ); +return PTR_ERR (keypad->clk); + } + keypad->irq =platform_get_irq (pdev,0 );if (keypad->irq <0 ) { error = keypad->irq;
@@ -424,7 +388,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)return error; } -device_init_wakeup (&pdev->dev, pdata->wakeup); + wakeup =device_property_read_bool (dev,"wakeup-source" ) || +/* legacy name */ +device_property_read_bool (dev,"linux,input-wakeup" ); +device_init_wakeup (&pdev->dev, wakeup); +platform_set_drvdata (pdev, keypad); error =devm_pm_runtime_enable (&pdev->dev);
@@ -435,14 +403,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)if (error)return error; -if (!dev_get_platdata (&pdev->dev)) { -if (pdata->keymap_data) { -devm_kfree (&pdev->dev, (void *)pdata->keymap_data->keymap); -devm_kfree (&pdev->dev, (void *)pdata->keymap_data); - } -devm_kfree (&pdev->dev, (void *)pdata); - } -return 0 ; }
include/linux/input/samsung-keypad.h deleted +0 -39
@@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Samsung Keypad platform data definitions -* -* Copyright (C) 2010 Samsung Electronics Co.Ltd -* Author: Joonyoung Shim <[email protected]> -*/ - -#ifndef __SAMSUNG_KEYPAD_H -#define __SAMSUNG_KEYPAD_H - -#include <linux/input/matrix_keypad.h> - -#define SAMSUNG_MAX_ROWS 8 -#define SAMSUNG_MAX_COLS 8 - -/** -* struct samsung_keypad_platdata - Platform device data for Samsung Keypad. -* @keymap_data: pointer to &matrix_keymap_data. -* @rows: number of keypad row supported. -* @cols: number of keypad col supported. -* @no_autorepeat: disable key autorepeat. -* @wakeup: controls whether the device should be set up as wakeup source. -* @cfg_gpio: configure the GPIO. -* -* Initialisation data specific to either the machine or the platform -* for the device driver to use or call-back when configuring gpio. -*/ -struct samsung_keypad_platdata { -const struct matrix_keymap_data *keymap_data; -unsigned int rows; -unsigned int cols; -bool no_autorepeat; -bool wakeup; - -void (*cfg_gpio)(unsigned int rows,unsigned int cols); -}; - -#endif /* __SAMSUNG_KEYPAD_H */
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 05/10] Input: samsung-keypad - remove support for platform data
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Premature IRQ enablement leads to unclocked hardware access and kernel panic. --
--- Patch [5]: [PATCH v3 05/10] Input: samsung-keypad - remove support for platform data --- commit 66287716c4c767b7655e9d4647ac5fd73fc2b713
Author: Dmitry Torokhov <[email protected]>
Input: samsung-keypad - remove support for platform data
This commit removes platform data support from the samsung-keypad driver, as there are no remaining users in the kernel. The driver now relies entirely on generic device properties for configuration.
Quoted 4 lines
drivers/input/keyboard/samsung-keypad.c +0
-0
[ ... ]
drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 398
Quoted 13 lines
drivers/input/keyboard/samsung-keypad.c +5
-1@@ -424,7 +388,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)return error; } -device_init_wakeup (&pdev->dev, pdata->wakeup); + wakeup =device_property_read_bool (dev,"wakeup-source" ) || +/* legacy name */ +device_property_read_bool (dev,"linux,input-wakeup" ); +device_init_wakeup (&pdev->dev, wakeup); +platform_set_drvdata (pdev, keypad); error =devm_pm_runtime_enable (&pdev->dev);
[Severity: High]
This is a pre-existing issue, but I noticed that the IRQ is requested and unmasked before runtime PM is enabled.
In samsung_keypad_probe(), devm_request_threaded_irq() is called just before this point without IRQF_NO_AUTOEN. If a pending interrupt is left by the bootloader or a spurious interrupt occurs, it will fire immediately.
When samsung_keypad_irq() executes, it calls pm_runtime_get_sync() (which skips enabling the clock because keypad->stopped is true at probe time) and then accesses hardware registers:
drivers/input/keyboard/samsung-keypad.c:samsung_keypad_irq() {
...
do {
readl(keypad->base + SAMSUNG_KEYIFSTSCLR);
...
}Can this unconditional access to unclocked peripheral registers trigger a synchronous external abort and result in a kernel panic?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Dmitry Torokhov
maintainerPATCH v3 6/10 ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys
In reply to Dmitry TorokhovSwitch the gpio-keys device to use software nodes/properties to describe the buttons and switches. This will allow dropping support for platform data from the gpio-keys driver in the future.
--- arch/arm/mach-s3c/mach-crag6410.c | 79 ++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 21 deletions(-)
arch/arm/mach-s3c/mach-crag6410.c +58 -21
@@ -18,6 +18,7 @@#include <linux/input/matrix_keypad.h> #include <linux/gpio.h> #include <linux/gpio/machine.h> +#include <linux/gpio/property.h> #include <linux/leds.h> #include <linux/delay.h> #include <linux/mmc/host.h>
@@ -228,32 +229,68 @@ static void __init crag6410_setup_keypad(void)pr_err ("failed to instantiate keypad device\n" ); } -static struct gpio_keys_button crag6410_gpio_keys[] = { - [0 ] = { - .code =KEY_SUSPEND , - .gpio =S3C64XX_GPL (10 ),/* EINT 18 */ - .type =EV_KEY , - .wakeup =1 , - .active_low =1 , - }, - [1 ] = { - .code =SW_FRONT_PROXIMITY , - .gpio =S3C64XX_GPN (11 ),/* EINT 11 */ - .type =EV_SW , - }, +static const struct software_node crag6410_gpio_keys_node = { + .name ="crag6410-gpio-keys" , }; -static struct gpio_keys_platform_data crag6410_gpio_keydata = { - .buttons = crag6410_gpio_keys, - .nbuttons =ARRAY_SIZE (crag6410_gpio_keys), +static const struct property_entry crag6410_suspend_key_props[] = { +PROPERTY_ENTRY_U32 ("linux,code" ,KEY_SUSPEND ), +PROPERTY_ENTRY_GPIO ("gpios" , +SAMSUNG_GPIO_NODE ('L' ),10 ,/* EINT 18 */ +GPIO_ACTIVE_LOW ), +PROPERTY_ENTRY_BOOL ("wakeup-source" ), + { } }; -static struct platform_device crag6410_gpio_keydev = { - .name ="gpio-keys" , - .id =0 , - .dev.platform_data = &crag6410_gpio_keydata, +static const struct software_node crag6410_suspend_key_node = { + .parent = &crag6410_gpio_keys_node, + .properties = crag6410_suspend_key_props, +}; + +static const struct property_entry crag6410_prox_sw_props[] = { +PROPERTY_ENTRY_U32 ("linux,input-type" ,EV_SW ), +PROPERTY_ENTRY_U32 ("linux,code" ,SW_FRONT_PROXIMITY ), +PROPERTY_ENTRY_GPIO ("gpios" , +SAMSUNG_GPIO_NODE ('N' ),11 ,/* EINT 11 */ +GPIO_ACTIVE_HIGH ), + { } +}; + +static const struct software_node crag6410_prox_sw_node = { + .parent = &crag6410_gpio_keys_node, + .properties = crag6410_prox_sw_props, }; +static const struct software_node *crag6410_gpio_keys_swnodes[] = { + &crag6410_gpio_keys_node, + &crag6410_suspend_key_node, + &crag6410_prox_sw_node, +NULL +}; + +static void __init crag6410_setup_gpio_keys (void ) +{ +struct platform_device_info keys_info = { + .name ="gpio-keys" , + .id =0 , + }; +struct platform_device *pd; +int err; + + err =software_node_register_node_group (crag6410_gpio_keys_swnodes); +if (err) { +pr_err ("failed to register gpio-keys software nodes: %d\n" , err); +return ; + } + + keys_info.fwnode =software_node_fwnode (&crag6410_gpio_keys_node); + + pd =platform_device_register_full (&keys_info); + err =PTR_ERR_OR_ZERO (pd); +if (err) +pr_err ("failed to create gpio-keys device: %d\n" , err); +} +static struct resource crag6410_dm9k_resource[] = { [0 ] =DEFINE_RES_MEM (S3C64XX_PA_XM0CSN5 ,2 ), [1 ] =DEFINE_RES_MEM (S3C64XX_PA_XM0CSN5 + (1 <<8 ),2 ),
@@ -397,7 +434,6 @@ static struct platform_device *crag6410_devs0[] __initdata = { &samsung_device_pwm, &s3c64xx_device_iis0, &s3c64xx_device_iis1, - &crag6410_gpio_keydev, }; static struct platform_device *crag6410_devs1[] __initdata = {
@@ -909,6 +945,7 @@ static void __init crag6410_machine_init(void)gpiod_add_lookup_table (&crag_leds_table);crag6410_setup_keypad (); +crag6410_setup_gpio_keys ();platform_add_devices (crag6410_devs1,ARRAY_SIZE (crag6410_devs1));gpio_led_register_device (-1 , &gpio_leds_pdata);
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 06/10] ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The conversion to software nodes implicitly changes the default debounce interval for the keys from…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The conversion to software nodes implicitly changes the default debounce interval for the keys from 0ms to 5ms. --
--- Patch [6]: [PATCH v3 06/10] ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys --- commit 69f758b0d4bf8ffd63c5e52869f8e01a5ad69545
Author: Dmitry Torokhov <[email protected]>
ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys
This commit switches the gpio-keys device on crag6410 to use software nodes and properties instead of platform data. This prepares the gpio-keys driver for the removal of legacy platform data support.
Quoted 3 lines
arch/arm/mach-s3c/mach-crag6410.c +0
-0
[ ... ]
Quoted 14 lines
arch/arm/mach-s3c/mach-crag6410.c +0
-14-static struct gpio_keys_button crag6410_gpio_keys[] = { - [0 ] = { - .code =KEY_SUSPEND , - .gpio =S3C64XX_GPL (10 ),/* EINT 18 */ - .type =EV_KEY , - .wakeup =1 , - .active_low =1 , - }, - [1 ] = { - .code =SW_FRONT_PROXIMITY , - .gpio =S3C64XX_GPN (11 ),/* EINT 11 */ - .type =EV_SW , - }, -};
[ ... ]
arch/arm/mach-s3c/mach-crag6410.c static void __init crag6410_setup_keypad(void) · line 248
Quoted 8 lines
arch/arm/mach-s3c/mach-crag6410.c +8
-0+static const struct property_entry crag6410_suspend_key_props[] = { +PROPERTY_ENTRY_U32 ("linux,code" ,KEY_SUSPEND ), +PROPERTY_ENTRY_GPIO ("gpios" , +SAMSUNG_GPIO_NODE ('L' ),10 ,/* EINT 18 */ +GPIO_ACTIVE_LOW ), +PROPERTY_ENTRY_BOOL ("wakeup-source" ), + { } +};
[Severity: Low]
Does this conversion implicitly change the debounce interval?
In the old platform data, the debounce interval defaulted to 0 since the struct field was zero-initialized. By not specifying a "debounce-interval" property here, won't the gpio-keys fwnode parser apply a 5ms default to this key?
Quoted 4 lines
arch/arm/mach-s3c/mach-crag6410.c +4
-0+ +static const struct software_node crag6410_suspend_key_node = { + .parent = &crag6410_gpio_keys_node, + .properties = crag6410_suspend_key_props,
arch/arm/mach-s3c/mach-crag6410.c static void __init crag6410_setup_keypad(void) · line 257
Quoted 10 lines
arch/arm/mach-s3c/mach-crag6410.c +10
-0+}; + +static const struct property_entry crag6410_prox_sw_props[] = { +PROPERTY_ENTRY_U32 ("linux,input-type" ,EV_SW ), +PROPERTY_ENTRY_U32 ("linux,code" ,SW_FRONT_PROXIMITY ), +PROPERTY_ENTRY_GPIO ("gpios" , +SAMSUNG_GPIO_NODE ('N' ),11 ,/* EINT 11 */ +GPIO_ACTIVE_HIGH ), + { } +};
[Severity: Low]
Similarly, does the proximity switch also unintentionally receive a 5ms debounce interval because the property is omitted here?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Dmitry Torokhov
maintainerPATCH v3 7/10 mfd: wm831x: support software nodes for DCDC regulators
In reply to Dmitry TorokhovAllow passing software nodes to wm831x DCDC regulators via PMIC platform data. This is useful for non-DT/non-ACPI platforms that want to associate device properties (like DVS GPIOs) with the regulator devices using software nodes.
We add 'dcdc_swnodes' to the PMIC platform data 'struct wm831x_pdata' and have the MFD core assign these software nodes to the buckv cells.
--- drivers/mfd/wm831x-core.c | 47 ++++++++++++++++++++++++++++++---------- include/linux/mfd/wm831x/pdata.h | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-)
drivers/mfd/wm831x-core.c +35 -12
@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/mfd/core.h> #include <linux/slab.h> +#include <linux/string.h> #include <linux/err.h> #include <linux/mfd/wm831x/core.h>
@@ -1449,6 +1450,32 @@ const struct of_device_id wm831x_of_match[] = { };EXPORT_SYMBOL_GPL (wm831x_of_match); +static int wm831x_add_devices (struct wm831x *wm831x,int wm831x_num, +const struct mfd_cell *cells,int num_cells) +{ +struct wm831x_pdata *pdata = &wm831x->pdata; +int i; + + struct mfd_cell *local_cells __free(kfree) = +kmemdup_array (cells, num_cells,sizeof (*cells),GFP_KERNEL ); +if (!local_cells) +return -ENOMEM ; + +for (i =0 ; i < num_cells; i++) { +struct mfd_cell *cell = &local_cells[i]; + +if (strcmp (cell->name,"wm831x-buckv" ) ==0 ) { +int id = cell->id -1 ; + +if (id >=0 && id <WM831X_MAX_DCDC ) + cell->swnode = pdata->dcdc_swnodes[id]; + } + } + +return mfd_add_devices (wm831x->dev, wm831x_num, local_cells, num_cells, +NULL ,0 ,NULL ); +} +/* * Instantiate the generic non-control parts of the device. */
@@ -1620,15 +1647,13 @@ int wm831x_device_init(struct wm831x *wm831x, int irq)/* The core device is up, instantiate the subdevices. */ switch (parent) {case WM8310 : - ret =mfd_add_devices (wm831x->dev, wm831x_num, - wm8310_devs,ARRAY_SIZE (wm8310_devs), -NULL ,0 ,NULL ); + ret =wm831x_add_devices (wm831x, wm831x_num, + wm8310_devs,ARRAY_SIZE (wm8310_devs));break ;case WM8311 : - ret =mfd_add_devices (wm831x->dev, wm831x_num, - wm8311_devs,ARRAY_SIZE (wm8311_devs), -NULL ,0 ,NULL ); + ret =wm831x_add_devices (wm831x, wm831x_num, + wm8311_devs,ARRAY_SIZE (wm8311_devs));if (!pdata->disable_touch) mfd_add_devices(wm831x->dev, wm831x_num, touch_devs, ARRAY_SIZE(touch_devs),
@@ -1636,9 +1661,8 @@ int wm831x_device_init(struct wm831x *wm831x, int irq)break ;case WM8312 : - ret =mfd_add_devices (wm831x->dev, wm831x_num, - wm8312_devs,ARRAY_SIZE (wm8312_devs), -NULL ,0 ,NULL ); + ret =wm831x_add_devices (wm831x, wm831x_num, + wm8312_devs,ARRAY_SIZE (wm8312_devs));if (!pdata->disable_touch) mfd_add_devices(wm831x->dev, wm831x_num, touch_devs, ARRAY_SIZE(touch_devs),
@@ -1649,9 +1673,8 @@ int wm831x_device_init(struct wm831x *wm831x, int irq)case WM8321 :case WM8325 :case WM8326 : - ret =mfd_add_devices (wm831x->dev, wm831x_num, - wm8320_devs,ARRAY_SIZE (wm8320_devs), -NULL ,0 ,NULL ); + ret =wm831x_add_devices (wm831x, wm831x_num, + wm8320_devs,ARRAY_SIZE (wm8320_devs));break ;default :
include/linux/mfd/wm831x/pdata.h +2 -0
@@ -12,6 +12,7 @@struct wm831x ;struct regulator_init_data ; +struct software_node ;struct wm831x_backlight_pdata {int isink;/** ISINK to use, 1 or 2 */
@@ -132,6 +133,7 @@ struct wm831x_pdata {struct wm831x_status_pdata *status[WM831X_MAX_STATUS ];/** DCDC1 = 0 and so on */ struct regulator_init_data *dcdc[WM831X_MAX_DCDC ]; +const struct software_node *dcdc_swnodes[WM831X_MAX_DCDC ];/** EPE1 = 0 and so on */ struct regulator_init_data *epe[WM831X_MAX_EPE ];/** LDO1 = 0 and so on */
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The patch dynamically duplicates and modifies an `mfd_cell` array to inject software nodes…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The patch dynamically duplicates and modifies an mfd_cell array to inject software nodes, directly violating MFD subsystem guidelines.
- [Low] The commit message description starts with a lowercase letter, violating MFD subsystem formatting rules.
--
--- Patch [7]: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators --- commit 3d69bbb3a9fcf1555157438b7a85ed2a2744e94b
Author: Dmitry Torokhov <[email protected]>
mfd: wm831x: support software nodes for DCDC regulators
This commit allows passing software nodes to wm831x DCDC regulators via PMIC platform data. It adds dcdc_swnodes to the PMIC platform data and dynamically assigns these software nodes to the buckv cells during device addition.
Quoted 1 line
mfd: wm831x: support software nodes for DCDC regulators
[Severity: Low]
This isn't a bug, but should the description after the subsystem prefix be capitalized? The MFD subsystem conventions generally expect:
"mfd: wm831x: Support software nodes for DCDC regulators".
Quoted 3 lines
drivers/mfd/wm831x-core.c +0
-0
[ ... ]
drivers/mfd/wm831x-core.c const struct of_device_id wm831x_of_match[] = { · line 1460
Quoted 12 lines
drivers/mfd/wm831x-core.c +8
-0@@ -1449,6 +1450,32 @@ const struct of_device_id wm831x_of_match[] = { };EXPORT_SYMBOL_GPL (wm831x_of_match); +static int wm831x_add_devices (struct wm831x *wm831x,int wm831x_num, +const struct mfd_cell *cells,int num_cells) +{ +struct wm831x_pdata *pdata = &wm831x->pdata; +int i; + + struct mfd_cell *local_cells __free(kfree) = +kmemdup_array (cells, num_cells,sizeof (*cells),GFP_KERNEL );
[Severity: Medium]
Does this code dynamically duplicate the mfd_cell array to amend it?
The MFD subsystem guidelines advise that mfd_cell arrays should remain static references, and we should avoid creating local copies for dynamic amendments. Is there an alternative way to pass the software nodes without allocating and modifying a duplicated cell array?
Quoted 17 lines
drivers/mfd/wm831x-core.c +17
-0+if (!local_cells) +return -ENOMEM ; + +for (i =0 ; i < num_cells; i++) { +struct mfd_cell *cell = &local_cells[i]; + +if (strcmp (cell->name,"wm831x-buckv" ) ==0 ) { +int id = cell->id -1 ; + +if (id >=0 && id <WM831X_MAX_DCDC ) + cell->swnode = pdata->dcdc_swnodes[id]; + } + } + +return mfd_add_devices (wm831x->dev, wm831x_num, local_cells, num_cells, +NULL ,0 ,NULL ); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Krzysztof Kozlowski
maintainerRe: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators
In reply to Dmitry TorokhovQuoted 8 lines · Dmitry Torokhov
Allow passing software nodes to wm831x DCDC regulators via PMIC platform data. This is useful for non-DT/non-ACPI platforms that want to associate device properties (like DVS GPIOs) with the regulator devices using software nodes.
We add '
dcdc_swnodes' to the PMIC platform data 'structwm831x_pdata' and have the MFD core assign these software nodes to the buckv cells.
Quoted 6 lines
Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>--- drivers/mfd/wm831x-core.c | 47 ++++++++++++++++++++++++++++++---------- include/linux/mfd/wm831x/pdata.h | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-)
I still need Ack for this from Lee... and the problem is that you did not Cc him.
Please resend everything or spin v4 with MFD maintainers included for acking.
Best regards,
Krzysztof
Dmitry Torokhov
maintainerRe: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators
Quoted 16 lines · Krzysztof Kozlowski
Quoted 8 lines · Dmitry Torokhov
Allow passing software nodes to wm831x DCDC regulators via PMIC platform data. This is useful for non-DT/non-ACPI platforms that want to associate device properties (like DVS GPIOs) with the regulator devices using software nodes.
We add '
dcdc_swnodes' to the PMIC platform data 'structwm831x_pdata' and have the MFD core assign these software nodes to the buckv cells.Quoted 6 lines
Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>--- drivers/mfd/wm831x-core.c | 47 ++++++++++++++++++++++++++++++---------- include/linux/mfd/wm831x/pdata.h | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-)
Quoted 2 lines
I still need Ack for this from Lee... and the problem is that you did not Cc him.
Hmm, indeed. not sure wheat happened...
Quoted 3 lines
Please resend everything or spin v4 with MFD maintainers included for acking.
Maybe you could take patches 1-6 now and then I'll continue with the rest of cleanups?
Thanks.
Signature · 1 line
Dmitry
Krzysztof Kozlowski
maintainerRe: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators
Quoted 20 lines · Dmitry Torokhov
Quoted 16 lines · Krzysztof Kozlowski
Quoted 8 lines · Dmitry Torokhov
Allow passing software nodes to wm831x DCDC regulators via PMIC platform data. This is useful for non-DT/non-ACPI platforms that want to associate device properties (like DVS GPIOs) with the regulator devices using software nodes.
We add '
dcdc_swnodes' to the PMIC platform data 'structwm831x_pdata' and have the MFD core assign these software nodes to the buckv cells.Quoted 6 lines
Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>--- drivers/mfd/wm831x-core.c | 47 ++++++++++++++++++++++++++++++---------- include/linux/mfd/wm831x/pdata.h | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-)Quoted 2 lines
I still need Ack for this from Lee... and the problem is that you did not Cc him.
Quoted 8 lines
Hmm, indeed. not sure wheat happened...
Quoted 3 lines
Please resend everything or spin v4 with MFD maintainers included for acking.
Maybe you could take patches 1-6 now and then I'll continue with the rest of cleanups?
Sure, that works for me.
Best regards,
Krzysztof
Lee Jones
maintainerRe: [PATCH v3 07/10] mfd: wm831x: support software nodes for DCDC regulators
In reply to Dmitry TorokhovQuoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Krzysztof Kozlowski
Quoted 14 lines · Dmitry Torokhov
Allow passing software nodes to wm831x DCDC regulators via PMIC platform data. This is useful for non-DT/non-ACPI platforms that want to associate device properties (like DVS GPIOs) with the regulator devices using software nodes.
We add '
dcdc_swnodes' to the PMIC platform data 'structwm831x_pdata' and have the MFD core assign these software nodes to the buckv cells.Assisted-by Antigravity:gemini-3.5-flashSigned-off-by Dmitry Torokhov <[email protected]>--- drivers/mfd/wm831x-core.c | 47 ++++++++++++++++++++++++++++++---------- include/linux/mfd/wm831x/pdata.h | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-)
Quoted 4 lines
Quoted 2 lines
I still need Ack for this from Lee... and the problem is that you did not Cc him.
Hmm, indeed. not sure wheat happened...
Always worth a try! =;-)
Signature · 1 line
Lee Jones
Dmitry Torokhov
maintainerPATCH v3 8/10 ARM: s3c: crag6410: convert PMIC DVS GPIO to software properties
In reply to Dmitry TorokhovConvert the PMIC DVS GPIO configuration from a legacy lookup table to software properties. We use the new 'dcdc_swnodes' field in 'struct wm831x_pdata' to pass the software node to the regulator driver. We keep the DVS configuration parameters (control source, startup state) in the platform data.
--- arch/arm/mach-s3c/mach-crag6410.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
arch/arm/mach-s3c/mach-crag6410.c +15 -19
@@ -456,6 +456,17 @@ static struct pca953x_platform_data crag6410_pca_data = { .irq_base = -1, }; +static const struct property_entry crag_dcdc1_properties[] = { +PROPERTY_ENTRY_GPIO ("dvs-gpios" , +SAMSUNG_GPIO_NODE ('K' ),0 ,GPIO_ACTIVE_HIGH ), + { } +}; + +static const struct software_node crag_dcdc1_swnode = { + .name ="wm831x-buckv-dcdc1" , + .properties = crag_dcdc1_properties, +}; +/* VDDARM is controlled by DVS1 connected to GPK(0) */ static struct wm831x_buckv_pdata vddarm_pdata = { .dvs_control_src =1 ,
@@ -633,6 +644,9 @@ static struct wm831x_pdata crag_pmic_pdata = { &vddint,/* DCDC2 */ &vddmem,/* DCDC3 */ }, + .dcdc_swnodes = { + &crag_dcdc1_swnode, + }, .ldo = { &vddsys, /* LDO1 */
@@ -656,24 +670,6 @@ static struct wm831x_pdata crag_pmic_pdata = { .touch = &touch_pdata, }; -/* -* VDDARM is eventually ending up as a regulator hanging on the MFD cell device -* "wm831x-buckv.1" spawn from drivers/mfd/wm831x-core.c. -* -* From the note on the platform data we can see that this is clearly DVS1 -* and assigned as dcdc1 resource to the MFD core which sets .id of the cell -* spawning the DVS1 platform device to 1, then the cell platform device -* name is calculated from 10*instance + id resulting in the device name -* "wm831x-buckv.11" -*/ -static struct gpiod_lookup_table crag_pmic_gpiod_table = { - .dev_id ="wm831x-buckv.11" , - .table = { -GPIO_LOOKUP ("GPIOK" ,0 ,"dvs" ,GPIO_ACTIVE_HIGH ), - { }, - }, -}; -static struct i2c_board_info i2c_devs0[] = { {I2C_BOARD_INFO ("24c08" ,0x50 ), }, {I2C_BOARD_INFO ("tca6408" ,0x20 ),
@@ -931,7 +927,7 @@ static void __init crag6410_machine_init(void)s3c_fb_set_platdata (&crag6410_lcd_pdata);dwc2_hsotg_set_platdata (&crag6410_hsotg_pdata); -gpiod_add_lookup_table (&crag_pmic_gpiod_table); +software_node_register (&crag_dcdc1_swnode);i2c_register_board_info (0 , i2c_devs0,ARRAY_SIZE (i2c_devs0));gpiod_add_lookup_table (&crag_wm1250_ev1_gpiod_table);i2c_register_board_info (1 , i2c_devs1,ARRAY_SIZE (i2c_devs1));
Signature · 1 line
2.55.0.795.g602f6c329a-goog
[email protected]
AI reviewRe: [PATCH v3 08/10] ARM: s3c: crag6410: convert PMIC DVS GPIO to software properties
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Dynamic amendment of mfd_cell array using kmemdup_array violates MFD guidelines. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Dynamic amendment of mfd_cell array using kmemdup_array violates MFD guidelines. --
--- Patch [8]: [PATCH v3 08/10] ARM: s3c: crag6410: convert PMIC DVS GPIO to software properties --- commit 71a506655ae9f68a5ef7d764d51d6d48703e4dcb
Author: Dmitry Torokhov <[email protected]>
ARM: s3c: crag6410: convert PMIC DVS GPIO to software properties
Convert the PMIC DVS GPIO configuration from a legacy lookup table to software properties. We use the new 'dcdc_swnodes' field in 'struct wm831x_pdata' to pass the software node to the regulator driver.
Quoted 4 lines
arch/arm/mach-s3c/mach-crag6410.c +0
-0
[ ... ]
arch/arm/mach-s3c/mach-crag6410.c static struct wm831x_pdata crag_pmic_pdata = { · line 649
Quoted 7 lines
arch/arm/mach-s3c/mach-crag6410.c +3
-0@@ -633,6 +644,9 @@ static struct wm831x_pdata crag_pmic_pdata = { &vddint,/* DCDC2 */ &vddmem,/* DCDC3 */ }, + .dcdc_swnodes = { + &crag_dcdc1_swnode, + },
[Severity: Medium]
Is it possible that populating the new 'dcdc_swnodes' field relies on the MFD core dynamically allocating and amending the mfd_cell array at runtime?
Looking at wm831x_add_devices() in drivers/mfd/wm831x-core.c, passing these software nodes causes the core driver to dynamically copy the cell array to inject the pointers:
drivers/mfd/wm831x-core.c:wm831x_add_devices() {
...
struct mfd_cell *local_cells __free(kfree) =
kmemdup_array(cells, num_cells, sizeof(*cells), GFP_KERNEL);
...
}The MFD subsystem guidelines explicitly state: "For mfd_cells, do not create local copies for dynamic amendments; always use static references." Could this approach be violating the subsystem's architectural rules against dynamic cell amendments?
Quoted 3 lines
arch/arm/mach-s3c/mach-crag6410.c +0
-0.ldo = { &vddsys, /* LDO1 */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Dmitry Torokhov
maintainerPATCH v3 9/10 ARM: s3c: crag6410: convert basic-mmio-gpio and LEDs to software properties
In reply to Dmitry TorokhovConvert the basic-mmio-gpio device and the GPIO-controlled LEDs on the Cragganmore 6410 board to use software nodes/properties. This allows removing the crag_leds_table GPIO lookup table.
--- arch/arm/mach-s3c/mach-crag6410.c | 117 +++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 53 deletions(-)
arch/arm/mach-s3c/mach-crag6410.c +64 -53
@@ -319,12 +319,17 @@ static const struct property_entry crag6410_mmgpio_props[] = { { } }; +static const struct software_node crag6410_mmgpio_node = { + .name ="basic-mmio-gpio" , + .properties = crag6410_mmgpio_props, +}; +static struct platform_device_info crag6410_mmgpio_devinfo = { .name ="basic-mmio-gpio" , .id =-1 , .res = crag6410_mmgpio_resource, .num_res =ARRAY_SIZE (crag6410_mmgpio_resource), - .properties = crag6410_mmgpio_props, + .swnode = &crag6410_mmgpio_node, };static struct platform_device speyside_device = {
@@ -835,61 +840,68 @@ static struct s3c_sdhci_platdata crag6410_hsmmc0_pdata = { .host_caps = MMC_CAP_POWER_OFF_CARD, }; -static const struct gpio_led gpio_leds[] = { - { - .name ="d13:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d14:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d15:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d16:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d17:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d18:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d19:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, - { - .name ="d20:green:" , - .default_state =LEDS_GPIO_DEFSTATE_ON , - }, +static const struct software_node crag6410_leds_node = { + .name ="leds-gpio" , }; -static struct gpiod_lookup_table crag_leds_table = { - .dev_id ="leds-gpio" , - .table = { -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,0 ,"cs" ,0 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,1 ,"cs" ,1 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,2 ,"cs" ,2 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,3 ,"cs" ,3 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,4 ,"cs" ,4 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,5 ,"cs" ,5 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,6 ,"cs" ,6 ,GPIO_ACTIVE_LOW ), -GPIO_LOOKUP_IDX ("basic-mmio-gpio" ,7 ,"cs" ,7 ,GPIO_ACTIVE_LOW ), - { }, - }, -}; +#define CRAG6410_LED_NODE (_idx, _name) \ +static const struct property_entry crag6410_led##_idx##_props[] = { \ + PROPERTY_ENTRY_STRING("label", _name), \ + PROPERTY_ENTRY_GPIO("gpios", &crag6410_mmgpio_node, \ + _idx, GPIO_ACTIVE_LOW), \ + PROPERTY_ENTRY_STRING("default-state", "on"), \ + { } \ +}; \ +static const struct software_node crag6410_led##_idx##_node = { \ + .parent = &crag6410_leds_node, \ + .properties = crag6410_led##_idx##_props, \ +} -static const struct gpio_led_platform_data gpio_leds_pdata = { - .leds = gpio_leds, - .num_leds =ARRAY_SIZE (gpio_leds), +CRAG6410_LED_NODE (0 ,"d13:green:" ); +CRAG6410_LED_NODE (1 ,"d14:green:" ); +CRAG6410_LED_NODE (2 ,"d15:green:" ); +CRAG6410_LED_NODE (3 ,"d16:green:" ); +CRAG6410_LED_NODE (4 ,"d17:green:" ); +CRAG6410_LED_NODE (5 ,"d18:green:" ); +CRAG6410_LED_NODE (6 ,"d19:green:" ); +CRAG6410_LED_NODE (7 ,"d20:green:" ); + +static const struct software_node *crag6410_leds_swnodes[] = { + &crag6410_leds_node, + &crag6410_led0_node, + &crag6410_led1_node, + &crag6410_led2_node, + &crag6410_led3_node, + &crag6410_led4_node, + &crag6410_led5_node, + &crag6410_led6_node, + &crag6410_led7_node, +NULL }; +static void __init crag6410_setup_leds (void ) +{ +struct platform_device_info leds_info = { + .name ="leds-gpio" , + .id =PLATFORM_DEVID_NONE , + }; +struct platform_device *pd; +int err; + + err =software_node_register_node_group (crag6410_leds_swnodes); +if (err) { +pr_err ("failed to register leds software nodes: %d\n" , err); +return ; + } + + leds_info.fwnode =software_node_fwnode (&crag6410_leds_node); + + pd =platform_device_register_full (&leds_info); + err =PTR_ERR_OR_ZERO (pd); +if (err) +pr_err ("failed to create leds-gpio device: %d\n" , err); +} +static struct dwc2_hsotg_plat crag6410_hsotg_pdata;static struct gpiod_lookup_table crag_spi0_gpiod_table = {
@@ -939,12 +951,11 @@ static void __init crag6410_machine_init(void)platform_add_devices (crag6410_devs0,ARRAY_SIZE (crag6410_devs0));platform_device_register_full (&crag6410_mmgpio_devinfo); -gpiod_add_lookup_table (&crag_leds_table);crag6410_setup_keypad ();crag6410_setup_gpio_keys ();platform_add_devices (crag6410_devs1,ARRAY_SIZE (crag6410_devs1)); -gpio_led_register_device (-1 , &gpio_leds_pdata); +crag6410_setup_leds ();regulator_has_full_constraints ();
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Dmitry Torokhov
maintainerPATCH v3 10/10 ARM: s3c: crag6410: convert remaining GPIO lookup tables to property entries
In reply to Dmitry TorokhovStatic property entries support defining GPIOs and are more similar to device tree properties and are not prone to losing link between device and a lookup table because of changes in device name. Convert the board to use them for WM1250 and SPI0 devices.
This also fixes issue with recent conversion to GPIO descriptors where GPIO lookup tables were specifying incorrect GPIO chip name ("GPIO<N>" vs "GP<N>").
--- arch/arm/mach-s3c/devs.c | 35 ----------------- arch/arm/mach-s3c/devs.h | 1 - arch/arm/mach-s3c/mach-crag6410.c | 83 ++++++++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 60 deletions(-)
arch/arm/mach-s3c/devs.c +0 -35
@@ -335,38 +335,3 @@ void __init dwc2_hsotg_set_platdata(struct dwc2_hsotg_plat *pd) npd->phy_exit = s3c_usb_phy_exit; }#endif /* CONFIG_S3C_DEV_USB_HSOTG */ - -#ifdef CONFIG_S3C64XX_DEV_SPI0 -static struct resource s3c64xx_spi0_resource[] = { - [0 ] =DEFINE_RES_MEM (S3C_PA_SPI0 ,SZ_256 ), - [1 ] =DEFINE_RES_IRQ (IRQ_SPI0 ), -}; - -struct platform_device s3c64xx_device_spi0 = { - .name ="s3c6410-spi" , - .id =0 , - .num_resources =ARRAY_SIZE (s3c64xx_spi0_resource), - .resource = s3c64xx_spi0_resource, - .dev = { - .dma_mask = &samsung_device_dma_mask, - .coherent_dma_mask =DMA_BIT_MASK (32 ), - }, -}; - -void __init s3c64xx_spi0_set_platdata (int src_clk_nr,int num_cs) -{ -struct s3c64xx_spi_info pd; - -/* Reject invalid configuration */ -if (!num_cs || src_clk_nr <0 ) { -pr_err ("%s: Invalid SPI configuration\n" , __func__); -return ; - } - - pd.num_cs = num_cs; - pd.src_clk_nr = src_clk_nr; - pd.cfg_gpio = s3c64xx_spi0_cfg_gpio; - -s3c_set_platdata (&pd,sizeof (pd), &s3c64xx_device_spi0); -} -#endif /* CONFIG_S3C64XX_DEV_SPI0 */
arch/arm/mach-s3c/devs.h +0 -1
@@ -27,7 +27,6 @@ extern struct platform_device *s3c24xx_uart_src[];extern struct platform_device s3c64xx_device_iis0;extern struct platform_device s3c64xx_device_iis1; -extern struct platform_device s3c64xx_device_spi0;extern struct platform_device s3c_device_fb;extern struct platform_device s3c_device_hsmmc0;
arch/arm/mach-s3c/mach-crag6410.c +59 -24
123 lines not on this page · raw message
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Krzysztof Kozlowski
maintainerQuoted 17 lines · Dmitry Torokhov
Hi,
This series converts the Samsung keypad driver and the Cragganmore 6410 board to generic device properties, allowing the removal of legacy platform data and GPIO lookup tables.
We rework the Samsung keypad driver to stop using platform data, utilizing a new compact matrix keypad binding. To support this on the Cragganmore board, we add infrastructure to associate software nodes with Samsung
gpio_chips, and add software node propagation support to the wm831x MFD core to route DVS GPIO to the PMIC regulator.Finally, we convert all peripherals on the Cragganmore board (including keypad, GPIO keys, PMIC, WM1250, SPI0, basic-mmio-gpio, and LEDs) to software properties. This allows us to eliminate all legacy GPIO lookup tables and fixes incorrect GPIO chip names from previous conversions.
Quoted 5 lines
Mark, it would be great if you could give this a spin on Cragganmore.
The majority of changes are in
arch/boardcode, with a couple of input matches and one for MFD. If everyone agrees maybe we can merge it all through the soc tree?
Yes, I could take it via samsung-soc. I assume I have your acks for unput parts.
Best regards,
Krzysztof
Dmitry Torokhov
maintainerQuoted 18 lines · Krzysztof Kozlowski
Quoted 17 lines · Dmitry Torokhov
Hi,
This series converts the Samsung keypad driver and the Cragganmore 6410 board to generic device properties, allowing the removal of legacy platform data and GPIO lookup tables.
We rework the Samsung keypad driver to stop using platform data, utilizing a new compact matrix keypad binding. To support this on the Cragganmore board, we add infrastructure to associate software nodes with Samsung
gpio_chips, and add software node propagation support to the wm831x MFD core to route DVS GPIO to the PMIC regulator.Finally, we convert all peripherals on the Cragganmore board (including keypad, GPIO keys, PMIC, WM1250, SPI0, basic-mmio-gpio, and LEDs) to software properties. This allows us to eliminate all legacy GPIO lookup tables and fixes incorrect GPIO chip names from previous conversions.
Quoted 8 lines
Quoted 5 lines
Mark, it would be great if you could give this a spin on Cragganmore.
The majority of changes are in
arch/boardcode, with a couple of input matches and one for MFD. If everyone agrees maybe we can merge it all through the soc tree?Yes, I could take it via samsung-soc. I assume I have your acks for unput parts.
Yes, of course.
Regarding Sashiko review:
- IRQ concerns are pre-existing and will be addressed in a separate series
- TOCTOU with device tree overlay changing DT properties in the middle of the probe I will not attempt to address. If this is a real concern it should be addressed globally
- Introduction of 5ms default debounce on proximity and suspend seem harmless
- Copying of MFD cells is necessary because we need to "mix in" software nodes from platform data. I originally tried to handle this is the regulator, but the result was worse as it needed to add software node to the device after it was created. Doing it in the core is much cleaner overall.
Thanks.
Signature · 1 line
Dmitry
Krzysztof Kozlowski
maintainerQuoted 17 lines · Dmitry Torokhov
Hi,
This series converts the Samsung keypad driver and the Cragganmore 6410 board to generic device properties, allowing the removal of legacy platform data and GPIO lookup tables.
We rework the Samsung keypad driver to stop using platform data, utilizing a new compact matrix keypad binding. To support this on the Cragganmore board, we add infrastructure to associate software nodes with Samsung
gpio_chips, and add software node propagation support to the wm831x MFD core to route DVS GPIO to the PMIC regulator.Finally, we convert all peripherals on the Cragganmore board (including keypad, GPIO keys, PMIC, WM1250, SPI0, basic-mmio-gpio, and LEDs) to software properties. This allows us to eliminate all legacy GPIO lookup tables and fixes incorrect GPIO chip names from previous conversions.
Quoted 7 lines
Mark, it would be great if you could give this a spin on Cragganmore.
The majority of changes are in
arch/boardcode, with a couple of input matches and one for MFD. If everyone agrees maybe we can merge it all through the soc tree?Thanks!
Appplied 1-6 with conflicts needing manual resolution around linux/gpio/legacy.h (commit 8c44b5f068a36d168687d64f3801c11d3252c1d2).
Best regards,
Krzysztof
Re: (subset) [PATCH v3 00/10] Remove support for platform data from samsung keypad
In reply to Dmitry TorokhovQuoted 11 lines · Dmitry Torokhov
This series converts the Samsung keypad driver and the Cragganmore 6410 board to generic device properties, allowing the removal of legacy platform data and GPIO lookup tables.
We rework the Samsung keypad driver to stop using platform data, utilizing a new compact matrix keypad binding. To support this on the Cragganmore board, we add infrastructure to associate software nodes with Samsung
gpio_chips, and add software node propagation support to the wm831x MFD core to route DVS GPIO to the PMIC regulator.[...]
Applied, thanks!
[01/10] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
https://git.kernel.org/krzk/linux/c/27d305325d2f3929e61105d465ef968ea39502ec [02/10] Input: samsung-keypad - handle compact binding https://git.kernel.org/krzk/linux/c/e8812411863552ebb153d7c856e60ef6deecfba4 [03/10] ARM: s3c: register and attach software nodes for Samsung gpio_chips https://git.kernel.org/krzk/linux/c/a01394e260d51b0b028735a9d71476c5c74280df [04/10] ARM: s3c: crag6410: switch keypad device to software properties https://git.kernel.org/krzk/linux/c/78b8efc99aa61c99c77ad1bf6129ba182a27b52a [05/10] Input: samsung-keypad - remove support for platform data https://git.kernel.org/krzk/linux/c/235cb99d39db4c80e3120d59e4c572dbb408f524 [06/10] ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys https://git.kernel.org/krzk/linux/c/c67c110d141b4347b864aa08ca86a1a492bff776
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>