Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mfd: max8925: fix dt code for backlight

The device-tree enablement for max8925 has several problems, but besides
the bindings being wrong (and not having seen review) there's also some
bad coding practices on how to fill in the platform_data from device tree.

I came across this since it causes a warning when compiling
mmp2_defconfig, and instead of doing the minimal fix to silence the
warning, I restructured the code a bit.

This silences the warning:
drivers/video/backlight/max8925_bl.c: In function 'max8925_backlight_probe':
drivers/video/backlight/max8925_bl.c:177:3: warning: statement with no effect [-Wunused-value]

Note that the bindings themselves need to be revisited too, but that will
affect more than just the backlight driver and is best done separately;
this just fixes the bad code for the backlight driver.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Olof Johansson <olof@lixom.net>

+21 -20
+21 -20
drivers/video/backlight/max8925_bl.c
··· 101 101 .get_brightness = max8925_backlight_get_brightness, 102 102 }; 103 103 104 - #ifdef CONFIG_OF 105 - static int max8925_backlight_dt_init(struct platform_device *pdev, 106 - struct max8925_backlight_pdata *pdata) 104 + static void max8925_backlight_dt_init(struct platform_device *pdev) 107 105 { 108 106 struct device_node *nproot = pdev->dev.parent->of_node, *np; 109 - int dual_string; 107 + struct max8925_backlight_pdata *pdata; 108 + u32 val; 110 109 111 - if (!nproot) 112 - return -ENODEV; 110 + if (!nproot || !IS_ENABLED(CONFIG_OF)) 111 + return; 112 + 113 + pdata = devm_kzalloc(&pdev->dev, 114 + sizeof(struct max8925_backlight_pdata), 115 + GFP_KERNEL); 116 + if (!pdata) 117 + return; 118 + 113 119 np = of_find_node_by_name(nproot, "backlight"); 114 120 if (!np) { 115 121 dev_err(&pdev->dev, "failed to find backlight node\n"); 116 - return -ENODEV; 122 + return; 117 123 } 118 124 119 - of_property_read_u32(np, "maxim,max8925-dual-string", &dual_string); 120 - pdata->dual_string = dual_string; 121 - return 0; 125 + if (!of_property_read_u32(np, "maxim,max8925-dual-string", &val)) 126 + pdata->dual_string = val; 127 + 128 + pdev->dev.platform_data = pdata; 122 129 } 123 - #else 124 - #define max8925_backlight_dt_init(x, y) (-1) 125 - #endif 126 130 127 131 static int max8925_backlight_probe(struct platform_device *pdev) 128 132 { 129 133 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); 130 - struct max8925_backlight_pdata *pdata = pdev->dev.platform_data; 134 + struct max8925_backlight_pdata *pdata; 131 135 struct max8925_backlight_data *data; 132 136 struct backlight_device *bl; 133 137 struct backlight_properties props; ··· 174 170 platform_set_drvdata(pdev, bl); 175 171 176 172 value = 0; 177 - if (pdev->dev.parent->of_node && !pdata) { 178 - pdata = devm_kzalloc(&pdev->dev, 179 - sizeof(struct max8925_backlight_pdata), 180 - GFP_KERNEL); 181 - max8925_backlight_dt_init(pdev, pdata); 182 - } 173 + if (!pdev->dev.platform_data) 174 + max8925_backlight_dt_init(pdev); 183 175 176 + pdata = pdev->dev.platform_data; 184 177 if (pdata) { 185 178 if (pdata->lxw_scl) 186 179 value |= (1 << 7);