mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] irqchip/gic-v3: check kasprintf() for failures
@ 2018-04-24  7:10 YueHaibing
  2018-04-24  7:21 ` Marc Zyngier
  0 siblings, 1 reply; 3+ messages in thread
From: YueHaibing @ 2018-04-24  7:10 UTC (permalink / raw)
  To: tglx, jason, marc.zyngier; +Cc: linux-kernel, YueHaibing

We should just return -ENOMEM here if the allocation fails,
otherwise it may cause a panic.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its-pci-msi.c      | 3 +++
 drivers/irqchip/irq-gic-v3-its-platform-msi.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its-pci-msi.c b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
index 25a98de..ef3911f 100644
--- a/drivers/irqchip/irq-gic-v3-its-pci-msi.c
+++ b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
@@ -160,6 +160,9 @@ its_pci_msi_parse_madt(struct acpi_subtable_header *header,
 	its_entry = (struct acpi_madt_generic_translator *)header;
 	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
 			      (long)its_entry->base_address);
+	if(!node_name)
+		return -ENOMEM;
+
 	dom_handle = iort_find_domain_token(its_entry->translation_id);
 	if (!dom_handle) {
 		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
diff --git a/drivers/irqchip/irq-gic-v3-its-platform-msi.c b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
index 8881a05..b676fb4 100644
--- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
+++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
@@ -126,6 +126,9 @@ its_pmsi_parse_madt(struct acpi_subtable_header *header,
 	its_entry = (struct acpi_madt_generic_translator *)header;
 	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
 			      (long)its_entry->base_address);
+	if(!node_name)
+		return -ENOMEM;
+
 	domain_handle = iort_find_domain_token(its_entry->translation_id);
 	if (!domain_handle) {
 		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
-- 
2.7.0

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

* Re: [PATCH] irqchip/gic-v3: check kasprintf() for failures
  2018-04-24  7:10 [PATCH] irqchip/gic-v3: check kasprintf() for failures YueHaibing
@ 2018-04-24  7:21 ` Marc Zyngier
  2018-04-24  7:45   ` YueHaibing
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Zyngier @ 2018-04-24  7:21 UTC (permalink / raw)
  To: YueHaibing; +Cc: tglx, jason, linux-kernel

On Tue, 24 Apr 2018 08:10:36 +0100,
YueHaibing wrote:
> 
> We should just return -ENOMEM here if the allocation fails,
> otherwise it may cause a panic.

Can you explain how? From what I can see, node_name is only used as a
parameter to pr_err/pr_info, which will perfectly deal with it by
printing "(null)", and not causing a panic. Am I missing something?

> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/irqchip/irq-gic-v3-its-pci-msi.c      | 3 +++
>  drivers/irqchip/irq-gic-v3-its-platform-msi.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its-pci-msi.c b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
> index 25a98de..ef3911f 100644
> --- a/drivers/irqchip/irq-gic-v3-its-pci-msi.c
> +++ b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
> @@ -160,6 +160,9 @@ its_pci_msi_parse_madt(struct acpi_subtable_header *header,
>  	its_entry = (struct acpi_madt_generic_translator *)header;
>  	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
>  			      (long)its_entry->base_address);
> +	if(!node_name)

Missing space.

> +		return -ENOMEM;
> +
>  	dom_handle = iort_find_domain_token(its_entry->translation_id);
>  	if (!dom_handle) {
>  		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
> diff --git a/drivers/irqchip/irq-gic-v3-its-platform-msi.c b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
> index 8881a05..b676fb4 100644
> --- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
> +++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
> @@ -126,6 +126,9 @@ its_pmsi_parse_madt(struct acpi_subtable_header *header,
>  	its_entry = (struct acpi_madt_generic_translator *)header;
>  	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
>  			      (long)its_entry->base_address);
> +	if(!node_name)
> +		return -ENOMEM;
> +
>  	domain_handle = iort_find_domain_token(its_entry->translation_id);
>  	if (!domain_handle) {
>  		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
> -- 
> 2.7.0
> 
> 

Thanks,

	M.

-- 
Jazz is not dead, it just smell funny.

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

* Re: [PATCH] irqchip/gic-v3: check kasprintf() for failures
  2018-04-24  7:21 ` Marc Zyngier
@ 2018-04-24  7:45   ` YueHaibing
  0 siblings, 0 replies; 3+ messages in thread
From: YueHaibing @ 2018-04-24  7:45 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: tglx, jason, linux-kernel


On 2018/4/24 15:21, Marc Zyngier wrote:
> On Tue, 24 Apr 2018 08:10:36 +0100,
> YueHaibing wrote:
>>
>> We should just return -ENOMEM here if the allocation fails,
>> otherwise it may cause a panic.
> 
> Can you explain how? From what I can see, node_name is only used as a
> parameter to pr_err/pr_info, which will perfectly deal with it by
> printing "(null)", and not causing a panic. Am I missing something?
> 
You are right

I just misunderstood,sorry for noise.

>>
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>  drivers/irqchip/irq-gic-v3-its-pci-msi.c      | 3 +++
>>  drivers/irqchip/irq-gic-v3-its-platform-msi.c | 3 +++
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/drivers/irqchip/irq-gic-v3-its-pci-msi.c b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
>> index 25a98de..ef3911f 100644
>> --- a/drivers/irqchip/irq-gic-v3-its-pci-msi.c
>> +++ b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
>> @@ -160,6 +160,9 @@ its_pci_msi_parse_madt(struct acpi_subtable_header *header,
>>  	its_entry = (struct acpi_madt_generic_translator *)header;
>>  	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
>>  			      (long)its_entry->base_address);
>> +	if(!node_name)
> 
> Missing space.
> 
>> +		return -ENOMEM;
>> +
>>  	dom_handle = iort_find_domain_token(its_entry->translation_id);
>>  	if (!dom_handle) {
>>  		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
>> diff --git a/drivers/irqchip/irq-gic-v3-its-platform-msi.c b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
>> index 8881a05..b676fb4 100644
>> --- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
>> +++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
>> @@ -126,6 +126,9 @@ its_pmsi_parse_madt(struct acpi_subtable_header *header,
>>  	its_entry = (struct acpi_madt_generic_translator *)header;
>>  	node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
>>  			      (long)its_entry->base_address);
>> +	if(!node_name)
>> +		return -ENOMEM;
>> +
>>  	domain_handle = iort_find_domain_token(its_entry->translation_id);
>>  	if (!domain_handle) {
>>  		pr_err("%s: Unable to locate ITS domain handle\n", node_name);
>> -- 
>> 2.7.0
>>
>>
> 
> Thanks,
> 
> 	M.
> 

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

end of thread, other threads:[~2018-04-24  7:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24  7:10 [PATCH] irqchip/gic-v3: check kasprintf() for failures YueHaibing
2018-04-24  7:21 ` Marc Zyngier
2018-04-24  7:45   ` YueHaibing

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®