On 06/05/14 23:43, Damien Nicolet wrote:
Fix static platform_device causing module unloading to fail Signed-off-by: Damien Nicolet <[email protected]> --- drivers/w1/w1_sunxi.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/w1/w1_sunxi.c b/drivers/w1/w1_sunxi.c index de24f06..59d2996 100644 --- a/drivers/w1/w1_sunxi.c +++ b/drivers/w1/w1_sunxi.c @@ -9,35 +9,51 @@ static int gpio = -1; module_param(gpio, int, 0444); MODULE_PARM_DESC(gpio, "w1 gpio pin number"); -static struct w1_gpio_platform_data w1_gpio_pdata = { - .pin = -1, - .is_open_drain = 0, -}; - -static struct platform_device w1_device = { - .name = "w1-gpio", - .id = -1, - .dev.platform_data = &w1_gpio_pdata, -}; +static struct platform_device *w1_device; static int __init w1_sunxi_init(void) { - int ret; - if (!gpio_is_valid(gpio)) { + int ret = 0; + struct w1_gpio_platform_data w1_gpio_pdata = { + .pin = gpio, + .is_open_drain = 0, + }; + + if (!gpio_is_valid(w1_gpio_pdata.pin)) { ret = script_parser_fetch("w1_para", "gpio", &gpio, sizeof(int)); if (ret || !gpio_is_valid(gpio)) { - pr_err("invalid gpio pin : %d\n", gpio); + pr_err("invalid gpio pin in fex configuration : %d\n", + gpio); return -EINVAL; } + w1_gpio_pdata.pin = gpio; } - w1_gpio_pdata.pin = gpio; - return platform_device_register(&w1_device); + + w1_device = platform_device_alloc("w1-gpio", 0); + if (!w1_device) + return -ENOMEM; + + ret = + platform_device_add_data(w1_device, &w1_gpio_pdata, + sizeof(struct w1_gpio_platform_data)); + if (ret) + goto err; + + ret = platform_device_add(w1_device); + if (ret) + goto err; + + return 0; + +err: + platform_device_put(w1_device); + return ret; } static void __exit w1_sunxi_exit(void) { - platform_device_unregister(&w1_device); + platform_device_unregister(w1_device); } module_init(w1_sunxi_init);
thank you, applied on stage/sunxi-3.4 cheers, Alejandro Mery -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
