linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
@ 2022-03-11 11:53 Dan Carpenter
  2022-03-22 13:33 ` Srinivasa Rao Mandadapu
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2022-03-11 11:53 UTC (permalink / raw)
  To: kbuild, Srinivasa Rao Mandadapu
  Cc: lkp, kbuild-all, Linux Memory Management List, Mark Brown,
	Venkata Prasad Potturu

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   71941773e143369a73c9c4a3b62fbb60736a1182
commit: 9e3d83c52844f955aa2975f78cee48bf9f72f5e1 [8752/11953] ASoC: codecs: Add power domains support in digital macro codecs
config: arm-randconfig-m031-20220310 (https://download.01.org/0day-ci/archive/20220311/202203111754.32TAMFKD-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'

vim +/ERR_PTR +53 sound/soc/codecs/lpass-macro-common.c

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  14  struct lpass_macro *lpass_macro_pds_init(struct device *dev)
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  15  {
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  16  	struct lpass_macro *l_pds;
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  17  	int ret;
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  18  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  19  	if (!of_find_property(dev->of_node, "power-domains", NULL))
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  20  		return NULL;

Returning NULL here will lead to a crash in tx_macro_runtime_resume()

When a function returns a mix of NULL and error pointers, then NULL
means the feature is deliberately disabled.  It's not an error, it's a
deliberate choice by the distro or sys admin.  The caller has to
be written to allow the feature to be disabled.

An example of this might be LEDs.  Maybe people don't want LEDs so code
has to asume that the led->ops pointer might be NULL and check for that
before dereferencing it.

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  21  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  22  	l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  23  	if (!l_pds)
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  24  		return ERR_PTR(-ENOMEM);

Good.

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  25  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  26  	l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro");
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  27  	if (IS_ERR_OR_NULL(l_pds->macro_pd))
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  28  		return NULL;

If this feature is optional then it should be:

	if (IS_ERR_OR_NULL(l_pds->macro_pd))
		return ERR_CAST(l_pds->macro_pd);

The admin deliberately chose to enable the feature so we can't just
ignore errors and convert them to NULL.

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  29  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  30  	ret = pm_runtime_get_sync(l_pds->macro_pd);

This is correct, but the documentation for pm_runtime_get_sync() says to
consider pm_runtime_resume_and_get() instead.  The error handling is
slightly different and easier.  I forget the details.

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  31  	if (ret < 0) {
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  32  		pm_runtime_put_noidle(l_pds->macro_pd);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  33  		goto macro_err;
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  34  	}
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  35  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  36  	l_pds->dcodec_pd = dev_pm_domain_attach_by_name(dev, "dcodec");
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  37  	if (IS_ERR_OR_NULL(l_pds->dcodec_pd))
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  38  		goto dcodec_err;

Again this IS_ERR_OR_NULL() check needs to preserve the error codes:

	if (IS_ERR_OR_NULL(l_pds->dcodec_pd)) {
		ret = PTR_ERR(l_pds->dcodec_pd);
		goto dcodec_err;
	}

9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  39  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  40  	ret = pm_runtime_get_sync(l_pds->dcodec_pd);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  41  	if (ret < 0) {
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  42  		pm_runtime_put_noidle(l_pds->dcodec_pd);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  43  		goto dcodec_sync_err;
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  44  	}
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  45  	return l_pds;
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  46  
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  47  dcodec_sync_err:
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  48  	dev_pm_domain_detach(l_pds->dcodec_pd, false);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  49  dcodec_err:
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  50  	pm_runtime_put(l_pds->macro_pd);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  51  macro_err:
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  52  	dev_pm_domain_detach(l_pds->macro_pd, false);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26 @53  	return ERR_PTR(ret);
9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  54  }

---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
  2022-03-11 11:53 [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR' Dan Carpenter
@ 2022-03-22 13:33 ` Srinivasa Rao Mandadapu
  2022-03-22 13:54   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Srinivasa Rao Mandadapu @ 2022-03-22 13:33 UTC (permalink / raw)
  To: Dan Carpenter, kbuild
  Cc: lkp, kbuild-all, Linux Memory Management List, Mark Brown,
	Venkata Prasad Potturu


On 3/11/2022 5:23 PM, Dan Carpenter wrote:
Thanks for Your time and valuable inputs Dan!!
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
> head:   71941773e143369a73c9c4a3b62fbb60736a1182
> commit: 9e3d83c52844f955aa2975f78cee48bf9f72f5e1 [8752/11953] ASoC: codecs: Add power domains support in digital macro codecs
> config: arm-randconfig-m031-20220310 (https://download.01.org/0day-ci/archive/20220311/202203111754.32TAMFKD-lkp@intel.com/config)
> compiler: arm-linux-gnueabi-gcc (GCC) 11.2.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> smatch warnings:
> sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
>
> vim +/ERR_PTR +53 sound/soc/codecs/lpass-macro-common.c
>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  14  struct lpass_macro *lpass_macro_pds_init(struct device *dev)
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  15  {
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  16  	struct lpass_macro *l_pds;
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  17  	int ret;
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  18
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  19  	if (!of_find_property(dev->of_node, "power-domains", NULL))
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  20  		return NULL;
>
> Returning NULL here will lead to a crash in tx_macro_runtime_resume()
>
> When a function returns a mix of NULL and error pointers, then NULL
> means the feature is deliberately disabled.  It's not an error, it's a
> deliberate choice by the distro or sys admin.  The caller has to
> be written to allow the feature to be disabled.
>
> An example of this might be LEDs.  Maybe people don't want LEDs so code
> has to asume that the led->ops pointer might be NULL and check for that
> before dereferencing it.

Actually, it's optional here. For some targets, with lpass ADSP enabled, 
power domains are not required.

So is the reason, returning NULL Here.

>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  21
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  22  	l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  23  	if (!l_pds)
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  24  		return ERR_PTR(-ENOMEM);
>
> Good.
>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  25
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  26  	l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro");
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  27  	if (IS_ERR_OR_NULL(l_pds->macro_pd))
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  28  		return NULL;
>
> If this feature is optional then it should be:
>
> 	if (IS_ERR_OR_NULL(l_pds->macro_pd))
> 		return ERR_CAST(l_pds->macro_pd);
>
> The admin deliberately chose to enable the feature so we can't just
> ignore errors and convert them to NULL.

Here it's not optional, if power domains feature is available then macro 
and dcodec power domains should be present.

So will update it like below.

	if (IS_ERR_OR_NULL(l_pds->macro_pd)) {
		ret = PTR_ERR(l_pds->macro_pd);
		goto macro_err;
	}

>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  29
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  30  	ret = pm_runtime_get_sync(l_pds->macro_pd);
>
> This is correct, but the documentation for pm_runtime_get_sync() says to
> consider pm_runtime_resume_and_get() instead.  The error handling is
> slightly different and easier.  I forget the details.
Okay. Will update accordingly.
>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  31  	if (ret < 0) {
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  32  		pm_runtime_put_noidle(l_pds->macro_pd);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  33  		goto macro_err;
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  34  	}
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  35
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  36  	l_pds->dcodec_pd = dev_pm_domain_attach_by_name(dev, "dcodec");
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  37  	if (IS_ERR_OR_NULL(l_pds->dcodec_pd))
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  38  		goto dcodec_err;
>
> Again this IS_ERR_OR_NULL() check needs to preserve the error codes:
>
> 	if (IS_ERR_OR_NULL(l_pds->dcodec_pd)) {
> 		ret = PTR_ERR(l_pds->dcodec_pd);
> 		goto dcodec_err;
> 	}
Okay. Will update accordingly.
>
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  39
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  40  	ret = pm_runtime_get_sync(l_pds->dcodec_pd);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  41  	if (ret < 0) {
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  42  		pm_runtime_put_noidle(l_pds->dcodec_pd);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  43  		goto dcodec_sync_err;
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  44  	}
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  45  	return l_pds;
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  46
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  47  dcodec_sync_err:
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  48  	dev_pm_domain_detach(l_pds->dcodec_pd, false);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  49  dcodec_err:
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  50  	pm_runtime_put(l_pds->macro_pd);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  51  macro_err:
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  52  	dev_pm_domain_detach(l_pds->macro_pd, false);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26 @53  	return ERR_PTR(ret);
> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  54  }
>
> ---
> 0-DAY CI Kernel Test Service
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
  2022-03-22 13:33 ` Srinivasa Rao Mandadapu
@ 2022-03-22 13:54   ` Dan Carpenter
  2022-03-22 14:02     ` Srinivasa Rao Mandadapu
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2022-03-22 13:54 UTC (permalink / raw)
  To: Srinivasa Rao Mandadapu
  Cc: kbuild, lkp, kbuild-all, Linux Memory Management List,
	Mark Brown, Venkata Prasad Potturu

On Tue, Mar 22, 2022 at 07:03:23PM +0530, Srinivasa Rao Mandadapu wrote:
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  14  struct lpass_macro *lpass_macro_pds_init(struct device *dev)
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  15  {
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  16  	struct lpass_macro *l_pds;
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  17  	int ret;
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  18
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  19  	if (!of_find_property(dev->of_node, "power-domains", NULL))
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  20  		return NULL;
> > 
> > Returning NULL here will lead to a crash in tx_macro_runtime_resume()
> > 
> > When a function returns a mix of NULL and error pointers, then NULL
> > means the feature is deliberately disabled.  It's not an error, it's a
> > deliberate choice by the distro or sys admin.  The caller has to
> > be written to allow the feature to be disabled.
> > 
> > An example of this might be LEDs.  Maybe people don't want LEDs so code
> > has to asume that the led->ops pointer might be NULL and check for that
> > before dereferencing it.
> 
> Actually, it's optional here. For some targets, with lpass ADSP enabled,
> power domains are not required.
> 
> So is the reason, returning NULL Here.
> 

Unfortunately, the caller is not written to handle NULLs so it will
crash.

sound/soc/codecs/lpass-tx-macro.c
  1913  static int tx_macro_remove(struct platform_device *pdev)
  1914  {
  1915          struct tx_macro *tx = dev_get_drvdata(&pdev->dev);
  1916  
  1917          clk_disable_unprepare(tx->macro);
  1918          clk_disable_unprepare(tx->dcodec);
  1919          clk_disable_unprepare(tx->mclk);
  1920          clk_disable_unprepare(tx->npl);
  1921          clk_disable_unprepare(tx->fsgen);
  1922  
  1923          lpass_macro_pds_exit(tx->pds);
                                     ^^^^^^^
Boom.

  1924  
  1925          return 0;
  1926  }


> > 
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  21
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  22  	l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL);
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  23  	if (!l_pds)
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  24  		return ERR_PTR(-ENOMEM);
> > 
> > Good.
> > 
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  25
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  26  	l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro");
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  27  	if (IS_ERR_OR_NULL(l_pds->macro_pd))
> > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  28  		return NULL;
> > 
> > If this feature is optional then it should be:
> > 
> > 	if (IS_ERR_OR_NULL(l_pds->macro_pd))
> > 		return ERR_CAST(l_pds->macro_pd);
> > 
> > The admin deliberately chose to enable the feature so we can't just
> > ignore errors and convert them to NULL.
> 
> Here it's not optional, if power domains feature is available then macro and
> dcodec power domains should be present.
> 
> So will update it like below.
> 
> 	if (IS_ERR_OR_NULL(l_pds->macro_pd)) {
> 		ret = PTR_ERR(l_pds->macro_pd);
> 		goto macro_err;
> 	}

I bet COMPILE_TEST allows this to compile without CONFIG_PM but there
isn't anything we can do about that...

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
  2022-03-22 13:54   ` Dan Carpenter
@ 2022-03-22 14:02     ` Srinivasa Rao Mandadapu
  2022-03-22 14:09       ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Srinivasa Rao Mandadapu @ 2022-03-22 14:02 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kbuild, lkp, kbuild-all, Linux Memory Management List,
	Mark Brown, Venkata Prasad Potturu


On 3/22/2022 7:24 PM, Dan Carpenter wrote:
Thanks for Your Time Dan!!!
> On Tue, Mar 22, 2022 at 07:03:23PM +0530, Srinivasa Rao Mandadapu wrote:
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  14  struct lpass_macro *lpass_macro_pds_init(struct device *dev)
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  15  {
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  16  	struct lpass_macro *l_pds;
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  17  	int ret;
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  18
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  19  	if (!of_find_property(dev->of_node, "power-domains", NULL))
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  20  		return NULL;
>>>
>>> Returning NULL here will lead to a crash in tx_macro_runtime_resume()
>>>
>>> When a function returns a mix of NULL and error pointers, then NULL
>>> means the feature is deliberately disabled.  It's not an error, it's a
>>> deliberate choice by the distro or sys admin.  The caller has to
>>> be written to allow the feature to be disabled.
>>>
>>> An example of this might be LEDs.  Maybe people don't want LEDs so code
>>> has to asume that the led->ops pointer might be NULL and check for that
>>> before dereferencing it.
>> Actually, it's optional here. For some targets, with lpass ADSP enabled,
>> power domains are not required.
>>
>> So is the reason, returning NULL Here.
>>
> Unfortunately, the caller is not written to handle NULLs so it will
> crash.

Yes agree. will add error check with in lpass_macro_pds_exit().

Will that make sense?

>
> sound/soc/codecs/lpass-tx-macro.c
>    1913  static int tx_macro_remove(struct platform_device *pdev)
>    1914  {
>    1915          struct tx_macro *tx = dev_get_drvdata(&pdev->dev);
>    1916
>    1917          clk_disable_unprepare(tx->macro);
>    1918          clk_disable_unprepare(tx->dcodec);
>    1919          clk_disable_unprepare(tx->mclk);
>    1920          clk_disable_unprepare(tx->npl);
>    1921          clk_disable_unprepare(tx->fsgen);
>    1922
>    1923          lpass_macro_pds_exit(tx->pds);
>                                       ^^^^^^^
> Boom.
>
>    1924
>    1925          return 0;
>    1926  }
>
>
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  21
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  22  	l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL);
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  23  	if (!l_pds)
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  24  		return ERR_PTR(-ENOMEM);
>>>
>>> Good.
>>>
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  25
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  26  	l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro");
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  27  	if (IS_ERR_OR_NULL(l_pds->macro_pd))
>>> 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  28  		return NULL;
>>>
>>> If this feature is optional then it should be:
>>>
>>> 	if (IS_ERR_OR_NULL(l_pds->macro_pd))
>>> 		return ERR_CAST(l_pds->macro_pd);
>>>
>>> The admin deliberately chose to enable the feature so we can't just
>>> ignore errors and convert them to NULL.
>> Here it's not optional, if power domains feature is available then macro and
>> dcodec power domains should be present.
>>
>> So will update it like below.
>>
>> 	if (IS_ERR_OR_NULL(l_pds->macro_pd)) {
>> 		ret = PTR_ERR(l_pds->macro_pd);
>> 		goto macro_err;
>> 	}
> I bet COMPILE_TEST allows this to compile without CONFIG_PM but there
> isn't anything we can do about that...
>
> regards,
> dan carpenter
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR'
  2022-03-22 14:02     ` Srinivasa Rao Mandadapu
@ 2022-03-22 14:09       ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-03-22 14:09 UTC (permalink / raw)
  To: Srinivasa Rao Mandadapu
  Cc: kbuild, lkp, kbuild-all, Linux Memory Management List,
	Mark Brown, Venkata Prasad Potturu

On Tue, Mar 22, 2022 at 07:32:16PM +0530, Srinivasa Rao Mandadapu wrote:
> 
> On 3/22/2022 7:24 PM, Dan Carpenter wrote:
> Thanks for Your Time Dan!!!
> > On Tue, Mar 22, 2022 at 07:03:23PM +0530, Srinivasa Rao Mandadapu wrote:
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  14  struct lpass_macro *lpass_macro_pds_init(struct device *dev)
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  15  {
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  16  	struct lpass_macro *l_pds;
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  17  	int ret;
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  18
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  19  	if (!of_find_property(dev->of_node, "power-domains", NULL))
> > > > 9e3d83c52844f95 Srinivasa Rao Mandadapu 2022-02-26  20  		return NULL;
> > > > 
> > > > Returning NULL here will lead to a crash in tx_macro_runtime_resume()
> > > > 
> > > > When a function returns a mix of NULL and error pointers, then NULL
> > > > means the feature is deliberately disabled.  It's not an error, it's a
> > > > deliberate choice by the distro or sys admin.  The caller has to
> > > > be written to allow the feature to be disabled.
> > > > 
> > > > An example of this might be LEDs.  Maybe people don't want LEDs so code
> > > > has to asume that the led->ops pointer might be NULL and check for that
> > > > before dereferencing it.
> > > Actually, it's optional here. For some targets, with lpass ADSP enabled,
> > > power domains are not required.
> > > 
> > > So is the reason, returning NULL Here.
> > > 
> > Unfortunately, the caller is not written to handle NULLs so it will
> > crash.
> 
> Yes agree. will add error check with in lpass_macro_pds_exit().
> 
> Will that make sense?

Yep.  Thanks!

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-22 14:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 11:53 [linux-next:master 8752/11953] sound/soc/codecs/lpass-macro-common.c:53 lpass_macro_pds_init() warn: passing zero to 'ERR_PTR' Dan Carpenter
2022-03-22 13:33 ` Srinivasa Rao Mandadapu
2022-03-22 13:54   ` Dan Carpenter
2022-03-22 14:02     ` Srinivasa Rao Mandadapu
2022-03-22 14:09       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox