lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <be070b91-4954-c66c-970c-a64f72eb54dc@loongson.cn>
Date:   Fri, 29 May 2020 10:03:54 +0800
From:   Tiezhu Yang <yangtiezhu@...ngson.cn>
To:     Stephen Boyd <sboyd@...nel.org>,
        Michael Turquette <mturquette@...libre.com>
Cc:     linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org,
        Xuefeng Li <lixuefeng@...ngson.cn>
Subject: Re: [PATCH v4 1/2] clk: hisilicon: Use correct return value about
 hisi_reset_init()

On 05/29/2020 07:15 AM, Stephen Boyd wrote:
> Quoting Tiezhu Yang (2020-05-27 19:27:42)
>> On 05/28/2020 03:06 AM, Stephen Boyd wrote:
>>> Quoting Tiezhu Yang (2020-05-27 07:39:21)
>>>> The return value about hisi_reset_init() is not correct, fix it.
>>>>
>>>> Fixes: e9a2310fb689 ("reset: hisilicon: fix potential NULL pointer dereference")
>>> hisi_reset_init() returns NULL on error in that commit. This patch
>>> doesn't make sense.
>> Hi Stephen,
>>
>> The initial aim of this patch is to use correct return value about
>> hisi_reset_init(), maybe NULL is OK, but the return value in this
>> patch is more accurate.
> The implementation of hisi_reset_init() that I see is this:
>
>
> 	struct hisi_reset_controller *rstc;
>
> 	rstc = devm_kmalloc(&pdev->dev, sizeof(*rstc), GFP_KERNEL);
> 	if (!rstc)
> 		return NULL;
>
> 	rstc->membase = devm_platform_ioremap_resource(pdev, 0);
> 	if (IS_ERR(rstc->membase))
> 		return NULL;
>
> 	spin_lock_init(&rstc->lock);
> 	rstc->rcdev.owner = THIS_MODULE;
> 	rstc->rcdev.ops = &hisi_reset_ops;
> 	rstc->rcdev.of_node = pdev->dev.of_node;
> 	rstc->rcdev.of_reset_n_cells = 2;
> 	rstc->rcdev.of_xlate = hisi_reset_of_xlate;
> 	reset_controller_register(&rstc->rcdev);
>
> 	return rstc;
>
> And that returns NULL on an error and a valid pointer on success.
> Changing the code to check the return value of hisi_reset_init() for an
> error pointer is simply wrong without updating hisi_reset_init() to
> return an error pointer on error. Where is the patch that changes
> hisi_reset_init() to return an error pointer?

Hi Stephen,

Do you mean the following changes?

diff --git a/drivers/clk/hisilicon/reset.c b/drivers/clk/hisilicon/reset.c
index 93cee17..c733e2e 100644
--- a/drivers/clk/hisilicon/reset.c
+++ b/drivers/clk/hisilicon/reset.c
@@ -93,11 +93,11 @@  struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev)
  
  	rstc = devm_kmalloc(&pdev->dev, sizeof(*rstc), GFP_KERNEL);
  	if (!rstc)
- return NULL;
+ return ERR_PTR(-ENOMEM);
  
  	rstc->membase = devm_platform_ioremap_resource(pdev, 0);
  	if (IS_ERR(rstc->membase))
- return NULL;
+ return ERR_CAST(rstc->membase);
  
  	spin_lock_init(&rstc->lock);
  	rstc->rcdev.owner = THIS_MODULE;


devm_platform_ioremap_resource()
          devm_ioremap_resource()
                  __devm_ioremap_resource()

By the way, we can see the comment of devm_ioremap_resource():

Usage example:

          res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
          base = devm_ioremap_resource(&pdev->dev, res);
          if (IS_ERR(base))
                  return PTR_ERR(base);


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ