* [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak
@ 2026-05-26 18:40 Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/drivers/clps711x: " Alexander A. Klimov
` (5 more replies)
0 siblings, 6 replies; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:40 UTC (permalink / raw)
To: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Michael Turquette, Stephen Boyd, Brian Masney,
moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
open list:COMMON CLK FRAMEWORK, open list
Cc: Alexander A. Klimov
Every value returned from of_clk_get() is supposed to be cleaned up
via clk_put() once not needed anymore.
Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
drivers/clk/mvebu/ap-cpu-clk.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/mvebu/ap-cpu-clk.c b/drivers/clk/mvebu/ap-cpu-clk.c
index 1e44ace7d951..7721d5fe50bc 100644
--- a/drivers/clk/mvebu/ap-cpu-clk.c
+++ b/drivers/clk/mvebu/ap-cpu-clk.c
@@ -312,6 +312,7 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
}
parent_name = __clk_get_name(parent);
clk_name[12] += cluster_index;
+ clk_put(parent);
ap_cpu_clk[cluster_index].clk_name =
ap_cp_unique_name(dev, np->parent, clk_name);
ap_cpu_clk[cluster_index].cluster = cluster_index;
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] clocksource/drivers/clps711x: fix refcount leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
@ 2026-05-26 18:40 ` Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/timer-econet-en751221: " Alexander A. Klimov
` (4 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:40 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner, Arnd Bergmann, Alexander Shiyan,
open list:CLOCKSOURCE, CLOCKEVENT DRIVERS
Cc: Alexander A. Klimov
Every value returned from of_clk_get() is supposed to be cleaned up
via clk_put() once not needed anymore.
Fixes: f0b7fabec327 ("clocksource: clps711x: Add CLPS711X clocksource driver")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
drivers/clocksource/clps711x-timer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c
index bb0a44adaf28..d9298a5f6005 100644
--- a/drivers/clocksource/clps711x-timer.c
+++ b/drivers/clocksource/clps711x-timer.c
@@ -76,7 +76,7 @@ static int __init _clps711x_clkevt_init(struct clk *clock, void __iomem *base,
static int __init clps711x_timer_init(struct device_node *np)
{
unsigned int irq = irq_of_parse_and_map(np, 0);
- struct clk *clock = of_clk_get(np, 0);
+ struct clk *clock;
void __iomem *base = of_iomap(np, 0);
int ret = 0;
@@ -86,6 +86,8 @@ static int __init clps711x_timer_init(struct device_node *np)
ret = -EINVAL;
goto unmap_io;
}
+
+ clock = of_clk_get(np, 0);
if (IS_ERR(clock)) {
ret = PTR_ERR(clock);
goto unmap_io;
@@ -103,6 +105,7 @@ static int __init clps711x_timer_init(struct device_node *np)
break;
}
+ clk_put(clock);
unmap_io:
iounmap(base);
return ret;
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] clocksource/timer-econet-en751221: fix refcount leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/drivers/clps711x: " Alexander A. Klimov
@ 2026-05-26 18:40 ` Alexander A. Klimov
2026-05-28 16:05 ` Caleb James DeLisle
2026-05-26 18:40 ` [PATCH] microblaze: CCF: " Alexander A. Klimov
` (3 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:40 UTC (permalink / raw)
To: Caleb James DeLisle, Daniel Lezcano, Thomas Gleixner,
open list:ECONET MIPS PLATFORM, open list:CLOCKSOURCE,
CLOCKEVENT DRIVERS
Cc: Alexander A. Klimov
Every value returned from of_clk_get() is supposed to be cleaned up
via clk_put() once not needed anymore.
Fixes: 3b4c33ac87d0 ("clocksource/drivers: Add EcoNet Timer HPT driver")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
drivers/clocksource/timer-econet-en751221.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clocksource/timer-econet-en751221.c b/drivers/clocksource/timer-econet-en751221.c
index 4008076b1a21..1859335345b5 100644
--- a/drivers/clocksource/timer-econet-en751221.c
+++ b/drivers/clocksource/timer-econet-en751221.c
@@ -181,6 +181,7 @@ static int __init timer_init(struct device_node *np)
}
econet_timer.freq_hz = clk_get_rate(clk);
+ clk_put(clk);
for (int i = 0; i < num_blocks; i++) {
econet_timer.membase[i] = of_iomap(np, i);
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] microblaze: CCF: fix refcount leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/drivers/clps711x: " Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/timer-econet-en751221: " Alexander A. Klimov
@ 2026-05-26 18:40 ` Alexander A. Klimov
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
` (2 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:40 UTC (permalink / raw)
To: Michal Simek, open list; +Cc: Alexander A. Klimov
Every value returned from of_clk_get() is supposed to be cleaned up
via clk_put() once not needed anymore.
Fixes: c1120542b99a ("microblaze: Add support for CCF")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
arch/microblaze/kernel/cpu/cpuinfo.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/microblaze/kernel/cpu/cpuinfo.c b/arch/microblaze/kernel/cpu/cpuinfo.c
index cd9b4450763b..32c508e85408 100644
--- a/arch/microblaze/kernel/cpu/cpuinfo.c
+++ b/arch/microblaze/kernel/cpu/cpuinfo.c
@@ -133,6 +133,7 @@ void __init setup_cpuinfo_clk(void)
cpuinfo.cpu_clock_freq = fcpu(cpu, "timebase-frequency");
} else {
cpuinfo.cpu_clock_freq = clk_get_rate(clk);
+ clk_put(clk);
}
if (!cpuinfo.cpu_clock_freq) {
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] drm/vc4: fix krealloc() memory leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
` (2 preceding siblings ...)
2026-05-26 18:40 ` [PATCH] microblaze: CCF: " Alexander A. Klimov
@ 2026-05-26 18:41 ` Alexander A. Klimov
2026-05-28 18:17 ` Maíra Canal
2026-05-26 18:41 ` [PATCH] ibmvnic: " Alexander A. Klimov
2026-05-26 22:41 ` [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Brian Masney
5 siblings, 1 reply; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:41 UTC (permalink / raw)
To: Maxime Ripard, Dave Stevenson, Maíra Canal,
Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Simona Vetter, Eric Anholt,
open list:DRM DRIVERS, open list
Cc: Alexander A. Klimov
Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:
MEM = krealloc(MEM, SZ, GFP);
If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:
TMP = krealloc(MEM, SZ, GFP);
if (!TMP) return;
MEM = TMP;
Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
index d48cf76983c0..af48758592f9 100644
--- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
+++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
@@ -291,14 +291,14 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
uint32_t o = validated_shader->num_uniform_addr_offsets;
uint32_t num_uniforms = validated_shader->uniforms_size / 4;
- validated_shader->uniform_addr_offsets =
- krealloc(validated_shader->uniform_addr_offsets,
- (o + 1) *
- sizeof(*validated_shader->uniform_addr_offsets),
- GFP_KERNEL);
- if (!validated_shader->uniform_addr_offsets)
+ void *mem = krealloc(validated_shader->uniform_addr_offsets,
+ (o + 1) *
+ sizeof(*validated_shader->uniform_addr_offsets),
+ GFP_KERNEL);
+ if (!mem)
return false;
+ validated_shader->uniform_addr_offsets = mem;
validated_shader->uniform_addr_offsets[o] = num_uniforms;
validated_shader->num_uniform_addr_offsets++;
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] ibmvnic: fix krealloc() memory leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
` (3 preceding siblings ...)
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
@ 2026-05-26 18:41 ` Alexander A. Klimov
2026-05-26 20:50 ` Nicolai Buchwitz
2026-05-26 22:41 ` [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Brian Masney
5 siblings, 1 reply; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-26 18:41 UTC (permalink / raw)
To: Haren Myneni, Rick Lindsley, Nick Child, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Thomas Falcon, Desnes Augusto Nunes do Rosario,
open list:IBM Power SRIOV Virtual NIC Device Driver,
open list:LINUX FOR POWERPC (32-BIT AND 64-BIT),
open list
Cc: Alexander A. Klimov
Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:
MEM = krealloc(MEM, SZ, GFP);
If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:
TMP = krealloc(MEM, SZ, GFP);
if (!TMP) return;
MEM = TMP;
Fixes: 4e6759be28e4 ("ibmvnic: Feature implementation of Vital Product Data (VPD) for the ibmvnic driver")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
drivers/net/ethernet/ibm/ibmvnic.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 5a510eed335e..25d1d844ad19 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1761,8 +1761,9 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
union ibmvnic_crq crq;
int len = 0;
int rc;
+ unsigned char *buff = adapter->vpd->buff;
- if (adapter->vpd->buff)
+ if (buff)
len = adapter->vpd->len;
mutex_lock(&adapter->fw_lock);
@@ -1788,17 +1789,17 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
if (!adapter->vpd->len)
return -ENODATA;
- if (!adapter->vpd->buff)
- adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
+ if (!buff)
+ buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
else if (adapter->vpd->len != len)
- adapter->vpd->buff =
- krealloc(adapter->vpd->buff,
- adapter->vpd->len, GFP_KERNEL);
+ buff = krealloc(buff,
+ adapter->vpd->len, GFP_KERNEL);
- if (!adapter->vpd->buff) {
+ if (!buff) {
dev_err(dev, "Could allocate VPD buffer\n");
return -ENOMEM;
}
+ adapter->vpd->buff = buff;
adapter->vpd->dma_addr =
dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len,
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] ibmvnic: fix krealloc() memory leak
2026-05-26 18:41 ` [PATCH] ibmvnic: " Alexander A. Klimov
@ 2026-05-26 20:50 ` Nicolai Buchwitz
2026-05-27 17:22 ` Alexander A. Klimov
0 siblings, 1 reply; 18+ messages in thread
From: Nicolai Buchwitz @ 2026-05-26 20:50 UTC (permalink / raw)
To: Alexander A. Klimov
Cc: Haren Myneni, Rick Lindsley, Nick Child, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Thomas Falcon, Desnes Augusto Nunes do Rosario,
netdev, linuxppc-dev, linux-kernel
Hi Alex
You patch is missing the prefix with the target tree. Please have
a look at [1] for more details on the workflow.
On 26.5.2026 20:41, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
>
> MEM = krealloc(MEM, SZ, GFP);
>
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
>
> TMP = krealloc(MEM, SZ, GFP);
> if (!TMP) return;
> MEM = TMP;
>
> Fixes: 4e6759be28e4 ("ibmvnic: Feature implementation of Vital Product
> Data (VPD) for the ibmvnic driver")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
> drivers/net/ethernet/ibm/ibmvnic.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/ibm/ibmvnic.c
> b/drivers/net/ethernet/ibm/ibmvnic.c
> index 5a510eed335e..25d1d844ad19 100644
> --- a/drivers/net/ethernet/ibm/ibmvnic.c
> +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> @@ -1761,8 +1761,9 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter
> *adapter)
> union ibmvnic_crq crq;
> int len = 0;
> int rc;
> + unsigned char *buff = adapter->vpd->buff;
Should be reverse x-mas tree (longest to shortest).
>
> - if (adapter->vpd->buff)
> + if (buff)
> len = adapter->vpd->len;
>
> mutex_lock(&adapter->fw_lock);
> @@ -1788,17 +1789,17 @@ static int ibmvnic_get_vpd(struct
> ibmvnic_adapter *adapter)
> if (!adapter->vpd->len)
> return -ENODATA;
>
> - if (!adapter->vpd->buff)
> - adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
> + if (!buff)
> + buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
> else if (adapter->vpd->len != len)
> - adapter->vpd->buff =
> - krealloc(adapter->vpd->buff,
> - adapter->vpd->len, GFP_KERNEL);
> + buff = krealloc(buff,
> + adapter->vpd->len, GFP_KERNEL);
Dead branch? The only caller, init_resources(), kzalloc()s a fresh vpd
right before, and resets run release_vpd_data() first, so vpd->buff is
always NULL here and kzalloc() above always wins. The leak can't
trigger,
which makes the Fixes tag misleading.
>
> - if (!adapter->vpd->buff) {
> + if (!buff) {
> dev_err(dev, "Could allocate VPD buffer\n");
> return -ENOMEM;
> }
> + adapter->vpd->buff = buff;
If you keep it anyway: on failure the old buffer stays in vpd->buff
while
vpd->len is already the new size, a mismatch the original avoided by
NULLing. kfree() it (krealloc() does not free on failure) and NULL
before
-ENOMEM.
>
> adapter->vpd->dma_addr =
> dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len,
[1] https://docs.kernel.org/process/maintainer-netdev.html
Thanks,
Nicolai
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
` (4 preceding siblings ...)
2026-05-26 18:41 ` [PATCH] ibmvnic: " Alexander A. Klimov
@ 2026-05-26 22:41 ` Brian Masney
5 siblings, 0 replies; 18+ messages in thread
From: Brian Masney @ 2026-05-26 22:41 UTC (permalink / raw)
To: Alexander A. Klimov
Cc: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Michael Turquette, Stephen Boyd,
moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
open list:COMMON CLK FRAMEWORK, open list
On Tue, May 26, 2026 at 08:40:56PM +0200, Alexander A. Klimov wrote:
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
>
> Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] ibmvnic: fix krealloc() memory leak
2026-05-26 20:50 ` Nicolai Buchwitz
@ 2026-05-27 17:22 ` Alexander A. Klimov
0 siblings, 0 replies; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-27 17:22 UTC (permalink / raw)
To: Nicolai Buchwitz
Cc: Haren Myneni, Rick Lindsley, Nick Child, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Thomas Falcon, Desnes Augusto Nunes do Rosario,
netdev, linuxppc-dev, linux-kernel
On 5/26/26 22:50, Nicolai Buchwitz wrote:
> Hi Alex
>
> You patch is missing the prefix with the target tree. Please have
> a look at [1] for more details on the workflow.
Damn. :-)
So far I've always got away with whatever I copied from the majority of
git log --oneline --follow FILE
>
> On 26.5.2026 20:41, Alexander A. Klimov wrote:
>> Don't just overwrite the original pointer passed to krealloc()
>> with its return value without checking latter:
>>
>> MEM = krealloc(MEM, SZ, GFP);
>>
>> If krealloc() returns NULL, that erases the pointer
>> to the still allocated memory, hence leaks this memory.
>> Instead, use a temporary variable, check it's not NULL
>> and only then assign it to the original pointer:
>>
>> TMP = krealloc(MEM, SZ, GFP);
>> if (!TMP) return;
>> MEM = TMP;
>>
>> Fixes: 4e6759be28e4 ("ibmvnic: Feature implementation of Vital Product Data (VPD) for the ibmvnic driver")
>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
>> ---
>> drivers/net/ethernet/ibm/ibmvnic.c | 15 ++++++++-------
>> 1 file changed, 8 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
>> index 5a510eed335e..25d1d844ad19 100644
>> --- a/drivers/net/ethernet/ibm/ibmvnic.c
>> +++ b/drivers/net/ethernet/ibm/ibmvnic.c
>> @@ -1761,8 +1761,9 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
>> union ibmvnic_crq crq;
>> int len = 0;
>> int rc;
>> + unsigned char *buff = adapter->vpd->buff;
>
> Should be reverse x-mas tree (longest to shortest).
>
>>
>> - if (adapter->vpd->buff)
>> + if (buff)
>> len = adapter->vpd->len;
>>
>> mutex_lock(&adapter->fw_lock);
>> @@ -1788,17 +1789,17 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
>> if (!adapter->vpd->len)
>> return -ENODATA;
>>
>> - if (!adapter->vpd->buff)
>> - adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
>> + if (!buff)
>> + buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
>> else if (adapter->vpd->len != len)
>> - adapter->vpd->buff =
>> - krealloc(adapter->vpd->buff,
>> - adapter->vpd->len, GFP_KERNEL);
>> + buff = krealloc(buff,
>> + adapter->vpd->len, GFP_KERNEL);
>
> Dead branch? The only caller, init_resources(), kzalloc()s a fresh vpd
> right before, and resets run release_vpd_data() first, so vpd->buff is
> always NULL here and kzalloc() above always wins. The leak can't trigger,
Cool! No leak = no problem = nothing to do here
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] clocksource/timer-econet-en751221: fix refcount leak
2026-05-26 18:40 ` [PATCH] clocksource/timer-econet-en751221: " Alexander A. Klimov
@ 2026-05-28 16:05 ` Caleb James DeLisle
0 siblings, 0 replies; 18+ messages in thread
From: Caleb James DeLisle @ 2026-05-28 16:05 UTC (permalink / raw)
To: Alexander A. Klimov, Daniel Lezcano, Thomas Gleixner,
open list:ECONET MIPS PLATFORM, open list:CLOCKSOURCE,
CLOCKEVENT DRIVERS
On 26/05/2026 20:40, Alexander A. Klimov wrote:
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
Thank you for this. Since I have an open patchset on this driver, I've
integrated your patch in v6.
Link:
https://lore.kernel.org/linux-mips/20260528140046.2897674-1-cjd@cjdns.fr/
Thanks,
Caleb
>
> Fixes: 3b4c33ac87d0 ("clocksource/drivers: Add EcoNet Timer HPT driver")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
> drivers/clocksource/timer-econet-en751221.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/clocksource/timer-econet-en751221.c b/drivers/clocksource/timer-econet-en751221.c
> index 4008076b1a21..1859335345b5 100644
> --- a/drivers/clocksource/timer-econet-en751221.c
> +++ b/drivers/clocksource/timer-econet-en751221.c
> @@ -181,6 +181,7 @@ static int __init timer_init(struct device_node *np)
> }
>
> econet_timer.freq_hz = clk_get_rate(clk);
> + clk_put(clk);
>
> for (int i = 0; i < num_blocks; i++) {
> econet_timer.membase[i] = of_iomap(np, i);
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] drm/vc4: fix krealloc() memory leak
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
@ 2026-05-28 18:17 ` Maíra Canal
2026-05-28 18:54 ` Alexander A. Klimov
2026-05-31 19:55 ` [PATCH v2] " Alexander A. Klimov
0 siblings, 2 replies; 18+ messages in thread
From: Maíra Canal @ 2026-05-28 18:17 UTC (permalink / raw)
To: Alexander A. Klimov, Maxime Ripard, Dave Stevenson,
Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Simona Vetter, Eric Anholt,
open list:DRM DRIVERS, open list
Hi Alexander,
LGTM, but a small styling nit:
On 26/05/26 15:41, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
>
> MEM = krealloc(MEM, SZ, GFP);
>
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
>
> TMP = krealloc(MEM, SZ, GFP);
> if (!TMP) return;
> MEM = TMP;
>
> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> index d48cf76983c0..af48758592f9 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> @@ -291,14 +291,14 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
> uint32_t o = validated_shader->num_uniform_addr_offsets;
> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
Declare the variable here.
>
> - validated_shader->uniform_addr_offsets =
> - krealloc(validated_shader->uniform_addr_offsets,
> - (o + 1) *
> - sizeof(*validated_shader->uniform_addr_offsets),
> - GFP_KERNEL);
> - if (!validated_shader->uniform_addr_offsets)
> + void *mem = krealloc(validated_shader->uniform_addr_offsets,
Instead of void *, you should probably use uint32_t *.
Best regards,
- Maíra
> + (o + 1) *
> + sizeof(*validated_shader->uniform_addr_offsets),
> + GFP_KERNEL);
> + if (!mem)
> return false;
>
> + validated_shader->uniform_addr_offsets = mem;
> validated_shader->uniform_addr_offsets[o] = num_uniforms;
> validated_shader->num_uniform_addr_offsets++;
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] drm/vc4: fix krealloc() memory leak
2026-05-28 18:17 ` Maíra Canal
@ 2026-05-28 18:54 ` Alexander A. Klimov
2026-05-28 19:01 ` Maíra Canal
2026-05-31 19:55 ` [PATCH v2] " Alexander A. Klimov
1 sibling, 1 reply; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-28 18:54 UTC (permalink / raw)
To: Maíra Canal, Maxime Ripard, Dave Stevenson,
Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Simona Vetter, Eric Anholt,
open list:DRM DRIVERS, open list
On 5/28/26 20:17, Maíra Canal wrote:
> Hi Alexander,
>
> LGTM, but a small styling nit:
>
> On 26/05/26 15:41, Alexander A. Klimov wrote:
>> Don't just overwrite the original pointer passed to krealloc()
>> with its return value without checking latter:
>>
>> MEM = krealloc(MEM, SZ, GFP);
>>
>> If krealloc() returns NULL, that erases the pointer
>> to the still allocated memory, hence leaks this memory.
>> Instead, use a temporary variable, check it's not NULL
>> and only then assign it to the original pointer:
>>
>> TMP = krealloc(MEM, SZ, GFP);
>> if (!TMP) return;
>> MEM = TMP;
>>
>> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
>> ---
>> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
>> index d48cf76983c0..af48758592f9 100644
>> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
>> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
>> @@ -291,14 +291,14 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
>> uint32_t o = validated_shader->num_uniform_addr_offsets;
>> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
>
> Declare the variable here.
Strange...
It comes already directly after num_uniforms, doesn't it?
At least when I apply my patch to Linus' master.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] drm/vc4: fix krealloc() memory leak
2026-05-28 18:54 ` Alexander A. Klimov
@ 2026-05-28 19:01 ` Maíra Canal
0 siblings, 0 replies; 18+ messages in thread
From: Maíra Canal @ 2026-05-28 19:01 UTC (permalink / raw)
To: Alexander A. Klimov, Maxime Ripard, Dave Stevenson,
Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Simona Vetter, Eric Anholt,
open list:DRM DRIVERS, open list
Hi Alexander,
On 28/05/26 15:54, Alexander A. Klimov wrote:
>
>
> On 5/28/26 20:17, Maíra Canal wrote:
>> Hi Alexander,
>>
>> LGTM, but a small styling nit:
>>
>> On 26/05/26 15:41, Alexander A. Klimov wrote:
>>> Don't just overwrite the original pointer passed to krealloc()
>>> with its return value without checking latter:
>>>
>>> MEM = krealloc(MEM, SZ, GFP);
>>>
>>> If krealloc() returns NULL, that erases the pointer
>>> to the still allocated memory, hence leaks this memory.
>>> Instead, use a temporary variable, check it's not NULL
>>> and only then assign it to the original pointer:
>>>
>>> TMP = krealloc(MEM, SZ, GFP);
>>> if (!TMP) return;
>>> MEM = TMP;
>>>
>>> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader
>>> validation.")
>>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
>>> ---
>>> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------
>>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/
>>> gpu/drm/vc4/vc4_validate_shaders.c
>>> index d48cf76983c0..af48758592f9 100644
>>> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
>>> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
>>> @@ -291,14 +291,14 @@ static bool
>>> require_uniform_address_uniform(struct vc4_validated_shader_info *va
>>> uint32_t o = validated_shader->num_uniform_addr_offsets;
>>> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
>>
>> Declare the variable here.
>
> Strange...
> It comes already directly after num_uniforms, doesn't it?
Yeah, it does. However, usually, we declare the variables and then we
proceed to the functions. Check, for example, the function
record_texture_sample() in vc4.
Best regards,
- Maíra
> At least when I apply my patch to Linus' master.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2] drm/vc4: fix krealloc() memory leak
2026-05-28 18:17 ` Maíra Canal
2026-05-28 18:54 ` Alexander A. Klimov
@ 2026-05-31 19:55 ` Alexander A. Klimov
2026-06-01 3:34 ` Joe Perches
1 sibling, 1 reply; 18+ messages in thread
From: Alexander A. Klimov @ 2026-05-31 19:55 UTC (permalink / raw)
Cc: Alexander A. Klimov, Maxime Ripard, Dave Stevenson,
Maíra Canal, Raspberry Pi Kernel Maintenance,
Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Eric Anholt, open list:DRM DRIVERS,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:
MEM = krealloc(MEM, SZ, GFP);
If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:
TMP = krealloc(MEM, SZ, GFP);
if (!TMP) return;
MEM = TMP;
Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
v2: Declare the variable explicitly
v2: Instead of void *, use u32 *
v2: While on it, enhance variable name
[✓] scripts/checkpatch.pl --strict
[✓] allmodconfig compiled (i686, LLVM)
[✓] localyesconfig booted (IBM T43)
Note to myself: use --in-reply-to=2b602ec6-d563-4fa0-a0c5-89b97a46abf9@igalia.com
drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
index d48cf76983c0..6f52b4db9cc9 100644
--- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
+++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
@@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
{
uint32_t o = validated_shader->num_uniform_addr_offsets;
uint32_t num_uniforms = validated_shader->uniforms_size / 4;
+ u32 *offsets;
- validated_shader->uniform_addr_offsets =
- krealloc(validated_shader->uniform_addr_offsets,
- (o + 1) *
- sizeof(*validated_shader->uniform_addr_offsets),
- GFP_KERNEL);
- if (!validated_shader->uniform_addr_offsets)
+ offsets = krealloc(validated_shader->uniform_addr_offsets,
+ (o + 1) *
+ sizeof(*validated_shader->uniform_addr_offsets),
+ GFP_KERNEL);
+ if (!offsets)
return false;
+ validated_shader->uniform_addr_offsets = offsets;
validated_shader->uniform_addr_offsets[o] = num_uniforms;
validated_shader->num_uniform_addr_offsets++;
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] drm/vc4: fix krealloc() memory leak
2026-05-31 19:55 ` [PATCH v2] " Alexander A. Klimov
@ 2026-06-01 3:34 ` Joe Perches
2026-06-06 12:38 ` [PATCH v3] " Alexander A. Klimov
0 siblings, 1 reply; 18+ messages in thread
From: Joe Perches @ 2026-06-01 3:34 UTC (permalink / raw)
To: Alexander A. Klimov
Cc: Maxime Ripard, Dave Stevenson, Maíra Canal,
Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Simona Vetter,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Eric Anholt, open list:DRM DRIVERS, open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:\b(?i:clang|llvm)\b
On Sun, 2026-05-31 at 21:55 +0200, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
[]
> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
[]
> @@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
> {
> uint32_t o = validated_shader->num_uniform_addr_offsets;
> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
> + u32 *offsets;
>
> - validated_shader->uniform_addr_offsets =
> - krealloc(validated_shader->uniform_addr_offsets,
> - (o + 1) *
> - sizeof(*validated_shader->uniform_addr_offsets),
> - GFP_KERNEL);
> - if (!validated_shader->uniform_addr_offsets)
> + offsets = krealloc(validated_shader->uniform_addr_offsets,
> + (o + 1) *
> + sizeof(*validated_shader->uniform_addr_offsets),
> + GFP_KERNEL);
krealloc_array ?
> + if (!offsets)
> return false;
>
> + validated_shader->uniform_addr_offsets = offsets;
> validated_shader->uniform_addr_offsets[o] = num_uniforms;
> validated_shader->num_uniform_addr_offsets++;
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v3] drm/vc4: fix krealloc() memory leak
2026-06-01 3:34 ` Joe Perches
@ 2026-06-06 12:38 ` Alexander A. Klimov
2026-06-06 13:32 ` Maíra Canal
2026-06-09 18:49 ` Maíra Canal
0 siblings, 2 replies; 18+ messages in thread
From: Alexander A. Klimov @ 2026-06-06 12:38 UTC (permalink / raw)
Cc: Alexander A. Klimov, Maxime Ripard, Dave Stevenson,
Maíra Canal, Raspberry Pi Kernel Maintenance,
Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Eric Anholt, open list:DRM DRIVERS,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:
MEM = krealloc(MEM, SZ, GFP);
If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:
TMP = krealloc(MEM, SZ, GFP);
if (!TMP) return;
MEM = TMP;
While on it, use krealloc_array().
Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
v2: Declare the variable explicitly
v2: Instead of void *, use u32 *
v2: While on it, enhance variable name
v3: Use krealloc_array()
[✓] scripts/checkpatch.pl --strict
[✓] allmodconfig compiled (i686, LLVM)
[✓] localyesconfig booted (IBM T43)
Note to myself: use --in-reply-to=e1edeadb7c161580a5cd5c7e642dc1b28db8ee86.camel@perches.com
drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
index d48cf76983c0..66502a6a4a8e 100644
--- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
+++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
@@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
{
uint32_t o = validated_shader->num_uniform_addr_offsets;
uint32_t num_uniforms = validated_shader->uniforms_size / 4;
+ u32 *offsets;
- validated_shader->uniform_addr_offsets =
- krealloc(validated_shader->uniform_addr_offsets,
- (o + 1) *
- sizeof(*validated_shader->uniform_addr_offsets),
- GFP_KERNEL);
- if (!validated_shader->uniform_addr_offsets)
+ offsets = krealloc_array(validated_shader->uniform_addr_offsets,
+ o + 1,
+ sizeof(*validated_shader->uniform_addr_offsets),
+ GFP_KERNEL);
+ if (!offsets)
return false;
+ validated_shader->uniform_addr_offsets = offsets;
validated_shader->uniform_addr_offsets[o] = num_uniforms;
validated_shader->num_uniform_addr_offsets++;
--
2.54.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] drm/vc4: fix krealloc() memory leak
2026-06-06 12:38 ` [PATCH v3] " Alexander A. Klimov
@ 2026-06-06 13:32 ` Maíra Canal
2026-06-09 18:49 ` Maíra Canal
1 sibling, 0 replies; 18+ messages in thread
From: Maíra Canal @ 2026-06-06 13:32 UTC (permalink / raw)
To: Alexander A. Klimov
Cc: Maxime Ripard, Dave Stevenson, Raspberry Pi Kernel Maintenance,
Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Eric Anholt, open list:DRM DRIVERS,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
On 06/06/26 09:38, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
>
> MEM = krealloc(MEM, SZ, GFP);
>
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
>
> TMP = krealloc(MEM, SZ, GFP);
> if (!TMP) return;
> MEM = TMP;
>
> While on it, use krealloc_array().
>
> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Best regards,
- Maíra
> ---
> v2: Declare the variable explicitly
> v2: Instead of void *, use u32 *
> v2: While on it, enhance variable name
> v3: Use krealloc_array()
>
> [✓] scripts/checkpatch.pl --strict
> [✓] allmodconfig compiled (i686, LLVM)
> [✓] localyesconfig booted (IBM T43)
>
> Note to myself: use --in-reply-to=e1edeadb7c161580a5cd5c7e642dc1b28db8ee86.camel@perches.com
>
> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> index d48cf76983c0..66502a6a4a8e 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> @@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
> {
> uint32_t o = validated_shader->num_uniform_addr_offsets;
> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
> + u32 *offsets;
>
> - validated_shader->uniform_addr_offsets =
> - krealloc(validated_shader->uniform_addr_offsets,
> - (o + 1) *
> - sizeof(*validated_shader->uniform_addr_offsets),
> - GFP_KERNEL);
> - if (!validated_shader->uniform_addr_offsets)
> + offsets = krealloc_array(validated_shader->uniform_addr_offsets,
> + o + 1,
> + sizeof(*validated_shader->uniform_addr_offsets),
> + GFP_KERNEL);
> + if (!offsets)
> return false;
>
> + validated_shader->uniform_addr_offsets = offsets;
> validated_shader->uniform_addr_offsets[o] = num_uniforms;
> validated_shader->num_uniform_addr_offsets++;
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] drm/vc4: fix krealloc() memory leak
2026-06-06 12:38 ` [PATCH v3] " Alexander A. Klimov
2026-06-06 13:32 ` Maíra Canal
@ 2026-06-09 18:49 ` Maíra Canal
1 sibling, 0 replies; 18+ messages in thread
From: Maíra Canal @ 2026-06-09 18:49 UTC (permalink / raw)
To: Alexander A. Klimov
Cc: Maxime Ripard, Dave Stevenson, Raspberry Pi Kernel Maintenance,
Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Eric Anholt, open list:DRM DRIVERS,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Hi Alexander,
On 06/06/26 09:38, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
>
> MEM = krealloc(MEM, SZ, GFP);
>
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
>
> TMP = krealloc(MEM, SZ, GFP);
> if (!TMP) return;
> MEM = TMP;
>
> While on it, use krealloc_array().
>
> Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Applied to drm/misc/kernel (drm-misc-fixes).
Best Regards,
- Maíra
> ---
> v2: Declare the variable explicitly
> v2: Instead of void *, use u32 *
> v2: While on it, enhance variable name
> v3: Use krealloc_array()
>
> [✓] scripts/checkpatch.pl --strict
> [✓] allmodconfig compiled (i686, LLVM)
> [✓] localyesconfig booted (IBM T43)
>
> Note to myself: use --in-reply-to=e1edeadb7c161580a5cd5c7e642dc1b28db8ee86.camel@perches.com
>
> drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> index d48cf76983c0..66502a6a4a8e 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
> @@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
> {
> uint32_t o = validated_shader->num_uniform_addr_offsets;
> uint32_t num_uniforms = validated_shader->uniforms_size / 4;
> + u32 *offsets;
>
> - validated_shader->uniform_addr_offsets =
> - krealloc(validated_shader->uniform_addr_offsets,
> - (o + 1) *
> - sizeof(*validated_shader->uniform_addr_offsets),
> - GFP_KERNEL);
> - if (!validated_shader->uniform_addr_offsets)
> + offsets = krealloc_array(validated_shader->uniform_addr_offsets,
> + o + 1,
> + sizeof(*validated_shader->uniform_addr_offsets),
> + GFP_KERNEL);
> + if (!offsets)
> return false;
>
> + validated_shader->uniform_addr_offsets = offsets;
> validated_shader->uniform_addr_offsets[o] = num_uniforms;
> validated_shader->num_uniform_addr_offsets++;
>
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-06-09 18:49 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-26 18:40 [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/drivers/clps711x: " Alexander A. Klimov
2026-05-26 18:40 ` [PATCH] clocksource/timer-econet-en751221: " Alexander A. Klimov
2026-05-28 16:05 ` Caleb James DeLisle
2026-05-26 18:40 ` [PATCH] microblaze: CCF: " Alexander A. Klimov
2026-05-26 18:41 ` [PATCH] drm/vc4: fix krealloc() memory leak Alexander A. Klimov
2026-05-28 18:17 ` Maíra Canal
2026-05-28 18:54 ` Alexander A. Klimov
2026-05-28 19:01 ` Maíra Canal
2026-05-31 19:55 ` [PATCH v2] " Alexander A. Klimov
2026-06-01 3:34 ` Joe Perches
2026-06-06 12:38 ` [PATCH v3] " Alexander A. Klimov
2026-06-06 13:32 ` Maíra Canal
2026-06-09 18:49 ` Maíra Canal
2026-05-26 18:41 ` [PATCH] ibmvnic: " Alexander A. Klimov
2026-05-26 20:50 ` Nicolai Buchwitz
2026-05-27 17:22 ` Alexander A. Klimov
2026-05-26 22:41 ` [PATCH] clk: mvebu: ap-cpu-clk: fix refcount leak Brian Masney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome