diff mbox series

soc: xilinx: Fix a memory leak in zynqmp_pm_remove()

Message ID 93ef923496b6c45a0baa59458099aed3a20b771a.1685346792.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New, archived
Headers show
Series soc: xilinx: Fix a memory leak in zynqmp_pm_remove() | expand

Commit Message

Christophe JAILLET May 29, 2023, 7:53 a.m. UTC
'rx_chan' is known to be NULL here.
Reverse the logic to free the mbox if it has been allocated.

Fixes: ffdbae28d9d1 ("drivers: soc: xilinx: Use mailbox IPI callback")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
'rx_chan' may be NULL, but mbox_free_channel() handles it.
Maybe it is more informative to keep a (useless) "if (rx_chan)" to tell
that it may not be allocated.


On my machine, compilation fails with gcc (Ubuntu 12.1.0-2ubuntu1~22.04):

  CC      drivers/soc/xilinx/zynqmp_power.o
drivers/soc/xilinx/zynqmp_power.c: In function ‘zynqmp_pm_probe’:
drivers/soc/xilinx/zynqmp_power.c:193:12: error: ‘pm_api_version’ is used uninitialized [-Werror=uninitialized]
  193 |         if (pm_api_version < ZYNQMP_PM_VERSION)
      |            ^
drivers/soc/xilinx/zynqmp_power.c:187:13: note: ‘pm_api_version’ was declared here
  187 |         u32 pm_api_version;
      |             ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors

I think that this warning is bogus and gcc is wrong.

But I don't know what to do with it :/
Anyway, it is un-realated to this patch.
---
 drivers/soc/xilinx/zynqmp_power.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Dan Carpenter May 29, 2023, 9:59 a.m. UTC | #1
On Mon, May 29, 2023 at 09:53:24AM +0200, Christophe JAILLET wrote:
> 'rx_chan' is known to be NULL here.
> Reverse the logic to free the mbox if it has been allocated.
> 
> Fixes: ffdbae28d9d1 ("drivers: soc: xilinx: Use mailbox IPI callback")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> 'rx_chan' may be NULL, but mbox_free_channel() handles it.
> Maybe it is more informative to keep a (useless) "if (rx_chan)" to tell
> that it may not be allocated.
> 
> 
> On my machine, compilation fails with gcc (Ubuntu 12.1.0-2ubuntu1~22.04):
> 
>   CC      drivers/soc/xilinx/zynqmp_power.o
> drivers/soc/xilinx/zynqmp_power.c: In function ‘zynqmp_pm_probe’:
> drivers/soc/xilinx/zynqmp_power.c:193:12: error: ‘pm_api_version’ is used uninitialized [-Werror=uninitialized]
>   193 |         if (pm_api_version < ZYNQMP_PM_VERSION)
>       |            ^
> drivers/soc/xilinx/zynqmp_power.c:187:13: note: ‘pm_api_version’ was declared here
>   187 |         u32 pm_api_version;
>       |             ^~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> I think that this warning is bogus and gcc is wrong.
> 
> But I don't know what to do with it :/
> Anyway, it is un-realated to this patch.

I bet GCC is correct.

Do you have CONFIG_ZYNQMP_FIRMWARE enabled in your .config?  This driver
can only be compiled with that enabled, but I've seen some of your
other patches depend on CONFIG_BROKEN so I think you're going outside of
the Kconfig rules.

regards,
dan carpenter
Christophe JAILLET May 29, 2023, 1:52 p.m. UTC | #2
Le 29/05/2023 à 11:59, Dan Carpenter a écrit :
> On Mon, May 29, 2023 at 09:53:24AM +0200, Christophe JAILLET wrote:
>> 'rx_chan' is known to be NULL here.
>> Reverse the logic to free the mbox if it has been allocated.
>>
>> Fixes: ffdbae28d9d1 ("drivers: soc: xilinx: Use mailbox IPI callback")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> 'rx_chan' may be NULL, but mbox_free_channel() handles it.
>> Maybe it is more informative to keep a (useless) "if (rx_chan)" to tell
>> that it may not be allocated.
>>
>>
>> On my machine, compilation fails with gcc (Ubuntu 12.1.0-2ubuntu1~22.04):
>>
>>    CC      drivers/soc/xilinx/zynqmp_power.o
>> drivers/soc/xilinx/zynqmp_power.c: In function ‘zynqmp_pm_probe’:
>> drivers/soc/xilinx/zynqmp_power.c:193:12: error: ‘pm_api_version’ is used uninitialized [-Werror=uninitialized]
>>    193 |         if (pm_api_version < ZYNQMP_PM_VERSION)
>>        |            ^
>> drivers/soc/xilinx/zynqmp_power.c:187:13: note: ‘pm_api_version’ was declared here
>>    187 |         u32 pm_api_version;
>>        |             ^~~~~~~~~~~~~~
>> cc1: all warnings being treated as errors
>>
>> I think that this warning is bogus and gcc is wrong.
>>
>> But I don't know what to do with it :/
>> Anyway, it is un-realated to this patch.
> 
> I bet GCC is correct.
> 
> Do you have CONFIG_ZYNQMP_FIRMWARE enabled in your .config?  This driver
> can only be compiled with that enabled, but I've seen some of your
> other patches depend on CONFIG_BROKEN so I think you're going outside of
> the Kconfig rules.
> 
> regards,
> dan carpenter
> 
> 

Ok, got it. This is for arm64.

make does not behave the same when you build a file or a directory.
Sometimes it is convenient, sometimes it is surprising.

On x86:
make -j7 drivers/soc/xilinx/zynqmp_power.o		--> fail
make -j7 drivers/soc/xilinx/				--> build nothing because I'm not on arm64


export ARCH=arm64
./make.cross -j7 drivers/soc/xilinx/zynqmp_power.o	--> OK

Thanks for the pointer.

CJ
diff mbox series

Patch

diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c
index 641dcc958911..62a7f6af9544 100644
--- a/drivers/soc/xilinx/zynqmp_power.c
+++ b/drivers/soc/xilinx/zynqmp_power.c
@@ -280,8 +280,7 @@  static int zynqmp_pm_remove(struct platform_device *pdev)
 	if (event_registered)
 		xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback, NULL);
 
-	if (!rx_chan)
-		mbox_free_channel(rx_chan);
+	mbox_free_channel(rx_chan);
 
 	return 0;
 }