Message ID | 20180924101150.23349-5-brgl@bgdev.pl (mailing list archive) |
---|---|
State | Rejected, archived |
Headers | show |
Series | devres: provide and use devm_kstrdup_const() | expand |
On Mon, Sep 24, 2018 at 12:11:50PM +0200, Bartosz Golaszewski wrote: > Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as > an example of how to use this new routine to shrink driver code. > > While we're at it: replace a call to kcalloc() with devm_kcalloc(). > @@ -352,8 +344,6 @@ static int plt_clk_probe(struct platform_device *pdev) > goto err_drop_mclk; > } > > - plt_clk_free_parent_names_loop(parent_names, data->nparents); > - > platform_set_drvdata(pdev, data); > return 0; I don't think this is a good example. You changed a behaviour here in the way that you keep all chunks of memory (even small enough for pointers) during entire life time of the driver, which pretty likely would be forever till next boot. In the original case the memory was freed immediately in probe either it fails or returns with success. NAK, sorry.
pon., 24 wrz 2018 o 13:23 Andy Shevchenko <andriy.shevchenko@linux.intel.com> napisał(a): > > On Mon, Sep 24, 2018 at 12:11:50PM +0200, Bartosz Golaszewski wrote: > > Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as > > an example of how to use this new routine to shrink driver code. > > > > While we're at it: replace a call to kcalloc() with devm_kcalloc(). > > > @@ -352,8 +344,6 @@ static int plt_clk_probe(struct platform_device *pdev) > > goto err_drop_mclk; > > } > > > > - plt_clk_free_parent_names_loop(parent_names, data->nparents); > > - > > platform_set_drvdata(pdev, data); > > return 0; > > I don't think this is a good example. > > You changed a behaviour here in the way that you keep all chunks of memory > (even small enough for pointers) during entire life time of the driver, which > pretty likely would be forever till next boot. > > In the original case the memory was freed immediately in probe either it fails > or returns with success. > > NAK, sorry. > > I see. I'd like to still merge patches 1-3 and then I'd come up with better examples for the next release cycle once these are in? Bart
On Mon, Sep 24, 2018 at 01:44:19PM +0200, Bartosz Golaszewski wrote: > pon., 24 wrz 2018 o 13:23 Andy Shevchenko > <andriy.shevchenko@linux.intel.com> napisał(a): > > > > On Mon, Sep 24, 2018 at 12:11:50PM +0200, Bartosz Golaszewski wrote: > > > Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as > > > an example of how to use this new routine to shrink driver code. > > > > > > While we're at it: replace a call to kcalloc() with devm_kcalloc(). > > > > > @@ -352,8 +344,6 @@ static int plt_clk_probe(struct platform_device *pdev) > > > goto err_drop_mclk; > > > } > > > > > > - plt_clk_free_parent_names_loop(parent_names, data->nparents); > > > - > > > platform_set_drvdata(pdev, data); > > > return 0; > > > > I don't think this is a good example. > > > > You changed a behaviour here in the way that you keep all chunks of memory > > (even small enough for pointers) during entire life time of the driver, which > > pretty likely would be forever till next boot. > > > > In the original case the memory was freed immediately in probe either it fails > > or returns with success. > > > > NAK, sorry. > > > > > > I see. > > I'd like to still merge patches 1-3 and then I'd come up with better > examples for the next release cycle once these are in? I'm fine with first three, though I can't come up with better example for you now. My previous comment solely to clk-pmc-atom code.
diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c index d977193842df..239197799ea3 100644 --- a/drivers/clk/x86/clk-pmc-atom.c +++ b/drivers/clk/x86/clk-pmc-atom.c @@ -247,14 +247,6 @@ static void plt_clk_unregister_fixed_rate_loop(struct clk_plt_data *data, plt_clk_unregister_fixed_rate(data->parents[i]); } -static void plt_clk_free_parent_names_loop(const char **parent_names, - unsigned int i) -{ - while (i--) - kfree_const(parent_names[i]); - kfree(parent_names); -} - static void plt_clk_unregister_loop(struct clk_plt_data *data, unsigned int i) { @@ -280,8 +272,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, if (!data->parents) return ERR_PTR(-ENOMEM); - parent_names = kcalloc(nparents, sizeof(*parent_names), - GFP_KERNEL); + parent_names = devm_kcalloc(&pdev->dev, nparents, + sizeof(*parent_names), GFP_KERNEL); if (!parent_names) return ERR_PTR(-ENOMEM); @@ -294,7 +286,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, err = PTR_ERR(data->parents[i]); goto err_unreg; } - parent_names[i] = kstrdup_const(clks[i].name, GFP_KERNEL); + parent_names[i] = devm_kstrdup_const(&pdev->dev, + clks[i].name, GFP_KERNEL); } data->nparents = nparents; @@ -302,7 +295,6 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, err_unreg: plt_clk_unregister_fixed_rate_loop(data, i); - plt_clk_free_parent_names_loop(parent_names, i); return ERR_PTR(err); } @@ -352,8 +344,6 @@ static int plt_clk_probe(struct platform_device *pdev) goto err_drop_mclk; } - plt_clk_free_parent_names_loop(parent_names, data->nparents); - platform_set_drvdata(pdev, data); return 0; @@ -362,7 +352,6 @@ static int plt_clk_probe(struct platform_device *pdev) err_unreg_clk_plt: plt_clk_unregister_loop(data, i); plt_clk_unregister_parents(data); - plt_clk_free_parent_names_loop(parent_names, data->nparents); return err; }