public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: angelogioacchino.delregno@collabora.com
Cc: linux-clk@vger.kernel.org, linux-mediatek@lists.infradead.org
Subject: [bug report] clk: mediatek: clk-mtk: Extend mtk_clk_simple_probe()
Date: Thu, 2 Feb 2023 16:05:56 +0300	[thread overview]
Message-ID: <Y9u1NNZ4I6w4vygt@kili> (raw)

Hello AngeloGioacchino Del Regno,

The patch 7b6183108c8c: "clk: mediatek: clk-mtk: Extend
mtk_clk_simple_probe()" from Jan 20, 2023, leads to the following
Smatch static checker warning:

drivers/clk/mediatek/clk-mtk.c:558 mtk_clk_simple_probe() info: returning a literal zero is cleaner
drivers/clk/mediatek/clk-mtk.c:581 mtk_clk_simple_probe() error: uninitialized symbol 'base'.
drivers/clk/mediatek/clk-mtk.c:583 mtk_clk_simple_probe() warn: 'base' from of_iomap() not released on lines: 496.

drivers/clk/mediatek/clk-mtk.c
   466  int mtk_clk_simple_probe(struct platform_device *pdev)
   467  {
   468          const struct mtk_clk_desc *mcd;
   469          struct clk_hw_onecell_data *clk_data;
   470          struct device_node *node = pdev->dev.of_node;
   471          void __iomem *base;
   472          int num_clks, r;
   473  
   474          mcd = of_device_get_match_data(&pdev->dev);
   475          if (!mcd)
   476                  return -EINVAL;
   477  
   478          /* Composite clocks needs us to pass iomem pointer */
   479          if (mcd->composite_clks) {
   480                  if (!mcd->shared_io)
   481                          base = devm_platform_ioremap_resource(pdev, 0);
   482                  else
   483                          base = of_iomap(node, 0);
   484  
   485                  if (IS_ERR_OR_NULL(base))
   486                          return IS_ERR(base) ? PTR_ERR(base) : -ENOMEM;
   487          }
   488  
   489          /* Calculate how many clk_hw_onecell_data entries to allocate */
   490          num_clks = mcd->num_clks + mcd->num_composite_clks;
   491          num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
   492          num_clks += mcd->num_mux_clks;
   493  
   494          clk_data = mtk_alloc_clk_data(num_clks);
   495          if (!clk_data)
   496                  return -ENOMEM;

goto free_base;

   497  
   498          if (mcd->fixed_clks) {
   499                  r = mtk_clk_register_fixed_clks(mcd->fixed_clks,
   500                                                  mcd->num_fixed_clks, clk_data);
   501                  if (r)
   502                          goto free_data;
   503          }
   504  
   505          if (mcd->factor_clks) {
   506                  r = mtk_clk_register_factors(mcd->factor_clks,
   507                                               mcd->num_factor_clks, clk_data);
   508                  if (r)
   509                          goto unregister_fixed_clks;
   510          }
   511  
   512          if (mcd->mux_clks) {
   513                  r = mtk_clk_register_muxes(&pdev->dev, mcd->mux_clks,
   514                                             mcd->num_mux_clks, node,
   515                                             mcd->clk_lock, clk_data);
   516                  if (r)
   517                          goto unregister_factors;
   518          };
   519  
   520          if (mcd->composite_clks) {
   521                  /* We don't check composite_lock because it's optional */
   522                  r = mtk_clk_register_composites(&pdev->dev,
   523                                                  mcd->composite_clks,
   524                                                  mcd->num_composite_clks,
   525                                                  base, mcd->clk_lock, clk_data);
   526                  if (r)
   527                          goto unregister_muxes;
   528          }
   529  
   530          if (mcd->clks) {
   531                  r = mtk_clk_register_gates(&pdev->dev, node, mcd->clks,
   532                                             mcd->num_clks, clk_data);
   533                  if (r)
   534                          goto unregister_composites;
   535          }
   536  
   537          if (mcd->clk_notifier_func) {
   538                  struct clk *mfg_mux = clk_data->hws[mcd->mfg_clk_idx]->clk;
   539  
   540                  r = mcd->clk_notifier_func(&pdev->dev, mfg_mux);
   541                  if (r)
   542                          goto unregister_clks;
   543          }
   544  
   545          r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
   546          if (r)
   547                  goto unregister_clks;
   548  
   549          platform_set_drvdata(pdev, clk_data);
   550  
   551          if (mcd->rst_desc) {
   552                  r = mtk_register_reset_controller_with_dev(&pdev->dev,
   553                                                             mcd->rst_desc);
   554                  if (r)
   555                          goto unregister_clks;
   556          }
   557  
   558          return r;

return 0;

   559  
   560  unregister_clks:
   561          if (mcd->clks)
   562                  mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
   563  unregister_composites:
   564          if (mcd->composite_clks)
   565                  mtk_clk_unregister_composites(mcd->composite_clks,
   566                                                mcd->num_composite_clks, clk_data);
   567  unregister_muxes:
   568          if (mcd->mux_clks)
   569                  mtk_clk_unregister_muxes(mcd->mux_clks,
   570                                           mcd->num_mux_clks, clk_data);
   571  unregister_factors:
   572          if (mcd->factor_clks)
   573                  mtk_clk_unregister_factors(mcd->factor_clks,
   574                                             mcd->num_factor_clks, clk_data);
   575  unregister_fixed_clks:
   576          if (mcd->fixed_clks)
   577                  mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
   578                                                mcd->num_fixed_clks, clk_data);
   579  free_data:
   580          mtk_free_clk_data(clk_data);
   581          if (mcd->shared_io && base)
   582                  iounmap(base);

This needs to be:

		if (mcd->composite_clks && !mcd->shared_io)
			iounmap(base);

   583          return r;
   584  }

regards,
dan carpenter

                 reply	other threads:[~2023-02-02 13:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Y9u1NNZ4I6w4vygt@kili \
    --to=error27@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    /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