From: John Garry <john.garry@huawei.com>
To: <xuwei5@huawei.com>
Cc: <bhelgaas@google.com>, <linuxarm@huawei.com>, <arm@kernel.org>,
<linux-kernel@vger.kernel.org>, <joe@perches.com>,
John Garry <john.garry@huawei.com>
Subject: [PATCH v2] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range
Date: Fri, 14 Jun 2019 18:24:53 +0800 [thread overview]
Message-ID: <1560507893-42553-1-git-send-email-john.garry@huawei.com> (raw)
If, after registering a logical PIO range, the driver probe later fails,
the logical PIO range memory will be released automatically.
This causes an issue, in that the logical PIO range is not unregistered
(that is not supported) and the released range memory may be later
referenced
Allocate the logical PIO range with kzalloc() to avoid this potential
issue.
Fixes: adf38bb0b5956 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
---
Change to v1:
- add comment, as advised by Joe Perches
diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
index 19d7b6ff2f17..5f0130a693fe 100644
--- a/drivers/bus/hisi_lpc.c
+++ b/drivers/bus/hisi_lpc.c
@@ -599,7 +599,8 @@ static int hisi_lpc_probe(struct platform_device *pdev)
if (IS_ERR(lpcdev->membase))
return PTR_ERR(lpcdev->membase);
- range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
+ /* Logical PIO may reference 'range' memory even if the probe fails */
+ range = kzalloc(sizeof(*range), GFP_KERNEL);
if (!range)
return -ENOMEM;
@@ -610,6 +611,7 @@ static int hisi_lpc_probe(struct platform_device *pdev)
ret = logic_pio_register_range(range);
if (ret) {
dev_err(dev, "register IO range failed (%d)!\n", ret);
+ kfree(range);
return ret;
}
lpcdev->io_host = range;
--
2.17.1
next reply other threads:[~2019-06-14 10:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 10:24 John Garry [this message]
2019-06-14 13:20 ` Bjorn Helgaas
2019-06-14 13:23 ` Bjorn Helgaas
[not found] ` <82840955-6365-0b95-6d69-8a2f7c7880af@huawei.com>
2019-06-14 21:56 ` Bjorn Helgaas
[not found] ` <9e8b6971-3189-9d4b-de9a-ff09f859f4f6@huawei.com>
2019-06-17 20:33 ` Bjorn Helgaas
2019-06-18 8:44 ` John Garry
2019-06-18 17:50 ` Bjorn Helgaas
2019-06-19 9:48 ` PCI host bridge hotplug test question (was Re: [PATCH v2] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range) John Garry
2019-06-19 9:53 ` John Garry
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=1560507893-42553-1-git-send-email-john.garry@huawei.com \
--to=john.garry@huawei.com \
--cc=arm@kernel.org \
--cc=bhelgaas@google.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=xuwei5@huawei.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
all inboxes | Powered by JetHome®