Linux clock framework development
 help / color / mirror / Atom feed
From: Rahul Tanwar <rtanwar@maxlinear.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
	linux-lgm-soc <linux-lgm-soc@maxlinear.com>
Subject: Re: [bug report] clk: mxl: Switch from direct readl/writel based IO to regmap based IO
Date: Tue, 25 Oct 2022 07:09:12 +0000	[thread overview]
Message-ID: <20852e6a-3c94-c878-43fa-f057f1507423@maxlinear.com> (raw)
In-Reply-To: <Y1Y31z6VqiuF/9Lp@kili>


Hi Dan,


On 24/10/2022 4:48 pm, Dan Carpenter wrote:
> This email was sent from outside of MaxLinear.
> 
> 
> Hello Rahul Tanwar,
> 
> The patch 036177310bac: "clk: mxl: Switch from direct readl/writel
> based IO to regmap based IO" from Oct 13, 2022, leads to the
> following Smatch static checker warning:
> 
>          drivers/clk/x86/clk-lgm.c:441 lgm_cgu_probe()
>          warn: passing zero to 'PTR_ERR'
> 
> drivers/clk/x86/clk-lgm.c
>      424 static int lgm_cgu_probe(struct platform_device *pdev)
>      425 {
>      426         struct lgm_clk_provider *ctx;
>      427         struct device *dev = &pdev->dev;
>      428         struct device_node *np = dev->of_node;
>      429         int ret;
>      430
>      431         ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, CLK_NR_CLKS),
>      432                            GFP_KERNEL);
>      433         if (!ctx)
>      434                 return -ENOMEM;
>      435
>      436         ctx->clk_data.num = CLK_NR_CLKS;
>      437
>      438         ctx->membase = syscon_node_to_regmap(np);
>      439         if (IS_ERR_OR_NULL(ctx->membase)) {
>      440                 dev_err(dev, "Failed to get clk CGU iomem\n");
> --> 441                 return PTR_ERR(ctx->membase);
> 
> Generally when a function returns NULL that is a special kind of success
> path where the feature has been deliberately disabled.  If for example,
> LEDs have been disabled then the ethernet driver or whatever should just
> handle that and continue functioning.  (If there is an error in the LEDs
> then report the error and do not ignore it).
> 
> Can this driver not continue without ctx->membase?  Is it useful to
> have a no-op probe function that just sets ctx->clk_data.num and returns
> success?  If it's not useful then it's better to handle it in the
> Kconfig instead of waiting for the user to find it the hard way.
> 
> If CONFIG_MFD_SYSCON is turned off then syscon_node_to_regmap() does
> not return NULL, it returns ERR_PTR(-ENOTSUPP).  So the IS_ERR_OR_NULL()
> doesn't make sense.
> 

Thanks for catching it. I agree with you that IS_ERR_OR_NULL() does not 
make sense here. It should have been IS_ERR(). I will send a fixup patch 
to fix it.

IMHO, it is not useful to have a no-op probe function without 
ctx->membase. Firstly, i have checked the syscon_node_to_regmap() 
function. It never returns NULL in any/all possible cases whether 
success or failure. Either it returns a valid membase pointer or error 
code. Secondly, if i approach to consider NULL return as special kind of 
success then i will have to return NULL for all clk_hw for all 
ctx->clk_data.num clks in order to make it a successfully probed & 
loaded driver but which offers no clk services at all i.e. makes all 
clks as dummy clks. That approach will need much more unnecessary code 
changes because the driver dynamically allocates all clk structures post 
syscon_node_to_regmap() call. Also, if the regbase is returned NULL then 
i do not see any point in loading the driver at all.

I will send a fixup patch to fix this static checker warning by 
replacing IS_ERR_OR_NULL() with IS_ERR().

Regards,
Rahul




>      442         }
>      443
>      444
>      445         ctx->np = np;
>      446         ctx->dev = dev;
>      447
>      448         ret = lgm_clk_register_plls(ctx, lgm_pll_clks,
>      449                                     ARRAY_SIZE(lgm_pll_clks));
>      450         if (ret)
>      451                 return ret;
>      452
>      453         ret = lgm_clk_register_branches(ctx, lgm_branch_clks,
>      454                                         ARRAY_SIZE(lgm_branch_clks));
>      455         if (ret)
>      456                 return ret;
>      457
>      458         ret = lgm_clk_register_ddiv(ctx, lgm_ddiv_clks,
>      459                                     ARRAY_SIZE(lgm_ddiv_clks));
>      460         if (ret)
>      461                 return ret;
>      462
>      463         return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
>      464                                            &ctx->clk_data);
>      465 }
> 
> regards,
> dan carpenter
> 
> 


      reply	other threads:[~2022-10-25  7:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24  6:59 [bug report] clk: mxl: Switch from direct readl/writel based IO to regmap based IO Dan Carpenter
2022-10-25  7:09 ` Rahul Tanwar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20852e6a-3c94-c878-43fa-f057f1507423@maxlinear.com \
    --to=rtanwar@maxlinear.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-lgm-soc@maxlinear.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox