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

Merge branch 'leds-fixes-for-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds

Pull LED subsystem bugfix from Bryan Wu.

* 'leds-fixes-for-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds:
leds: pwm: Fix for deferred probe in DT booted mode

+26 -27
+26 -27
drivers/leds/leds-pwm.c
··· 82 82 (sizeof(struct led_pwm_data) * num_leds); 83 83 } 84 84 85 - static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev) 85 + static int led_pwm_create_of(struct platform_device *pdev, 86 + struct led_pwm_priv *priv) 86 87 { 87 88 struct device_node *node = pdev->dev.of_node; 88 89 struct device_node *child; 89 - struct led_pwm_priv *priv; 90 - int count, ret; 91 - 92 - /* count LEDs in this device, so we know how much to allocate */ 93 - count = of_get_child_count(node); 94 - if (!count) 95 - return NULL; 96 - 97 - priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count), 98 - GFP_KERNEL); 99 - if (!priv) 100 - return NULL; 90 + int ret; 101 91 102 92 for_each_child_of_node(node, child) { 103 93 struct led_pwm_data *led_dat = &priv->leds[priv->num_leds]; ··· 99 109 if (IS_ERR(led_dat->pwm)) { 100 110 dev_err(&pdev->dev, "unable to request PWM for %s\n", 101 111 led_dat->cdev.name); 112 + ret = PTR_ERR(led_dat->pwm); 102 113 goto err; 103 114 } 104 115 /* Get the period from PWM core when n*/ ··· 128 137 priv->num_leds++; 129 138 } 130 139 131 - return priv; 140 + return 0; 132 141 err: 133 142 while (priv->num_leds--) 134 143 led_classdev_unregister(&priv->leds[priv->num_leds].cdev); 135 144 136 - return NULL; 145 + return ret; 137 146 } 138 147 139 148 static int led_pwm_probe(struct platform_device *pdev) 140 149 { 141 150 struct led_pwm_platform_data *pdata = dev_get_platdata(&pdev->dev); 142 151 struct led_pwm_priv *priv; 143 - int i, ret = 0; 152 + int count, i; 153 + int ret = 0; 144 154 145 - if (pdata && pdata->num_leds) { 146 - priv = devm_kzalloc(&pdev->dev, 147 - sizeof_pwm_leds_priv(pdata->num_leds), 148 - GFP_KERNEL); 149 - if (!priv) 150 - return -ENOMEM; 155 + if (pdata) 156 + count = pdata->num_leds; 157 + else 158 + count = of_get_child_count(pdev->dev.of_node); 151 159 152 - for (i = 0; i < pdata->num_leds; i++) { 160 + if (!count) 161 + return -EINVAL; 162 + 163 + priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count), 164 + GFP_KERNEL); 165 + if (!priv) 166 + return -ENOMEM; 167 + 168 + if (pdata) { 169 + for (i = 0; i < count; i++) { 153 170 struct led_pwm *cur_led = &pdata->leds[i]; 154 171 struct led_pwm_data *led_dat = &priv->leds[i]; 155 172 ··· 187 188 if (ret < 0) 188 189 goto err; 189 190 } 190 - priv->num_leds = pdata->num_leds; 191 + priv->num_leds = count; 191 192 } else { 192 - priv = led_pwm_create_of(pdev); 193 - if (!priv) 194 - return -ENODEV; 193 + ret = led_pwm_create_of(pdev, priv); 194 + if (ret) 195 + return ret; 195 196 } 196 197 197 198 platform_set_drvdata(pdev, priv);