diff mbox series

[v3] hw/cxl: Fix CFMW config memory leak

Message ID 20230531060706.11840-1-lizhijian@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show
Series [v3] hw/cxl: Fix CFMW config memory leak | expand

Commit Message

Li Zhijian May 31, 2023, 6:07 a.m. UTC
Allocate targets and targets[n] resources when all sanity checks are
passed to avoid memory leaks.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
V3: allocte further resource when we can't fail # Philippe
V2: Delete unnecesarry check
---
 hw/cxl/cxl-host.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Philippe Mathieu-Daudé May 31, 2023, 7:51 a.m. UTC | #1
On 31/5/23 08:07, Li Zhijian wrote:
> Allocate targets and targets[n] resources when all sanity checks are
> passed to avoid memory leaks.
> 
> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> ---
> V3: allocte further resource when we can't fail # Philippe

Thanks for the v3!

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> V2: Delete unnecesarry check
> ---
>   hw/cxl/cxl-host.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
Jonathan Cameron May 31, 2023, 11:08 a.m. UTC | #2
On Wed, 31 May 2023 09:51:43 +0200
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> On 31/5/23 08:07, Li Zhijian wrote:
> > Allocate targets and targets[n] resources when all sanity checks are
> > passed to avoid memory leaks.
> > 
> > Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> > Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> > ---
> > V3: allocte further resource when we can't fail # Philippe  
> 
> Thanks for the v3!
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks.  I've added this near the top of my queue so will send
it out along with other similar fixes as a series for Michael
to consider picking up.

Jonathan

> 
> > V2: Delete unnecesarry check
> > ---
> >   hw/cxl/cxl-host.c | 12 ++++++------
> >   1 file changed, 6 insertions(+), 6 deletions(-)  
>
Michael Tokarev Aug. 5, 2023, 5:46 a.m. UTC | #3
31.05.2023 14:08, Jonathan Cameron via wrote:
> On Wed, 31 May 2023 09:51:43 +0200
> Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> 
>> On 31/5/23 08:07, Li Zhijian wrote:
>>> Allocate targets and targets[n] resources when all sanity checks are
>>> passed to avoid memory leaks.
>>>
>>> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
>>> ---
>>> V3: allocte further resource when we can't fail # Philippe
>>
>> Thanks for the v3!
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Thanks.  I've added this near the top of my queue so will send
> it out along with other similar fixes as a series for Michael
> to consider picking up.

Hi!

Has this been forgotten? Is it still needed?

/mjt
Jonathan Cameron Aug. 8, 2023, 2:44 p.m. UTC | #4
On Sat, 5 Aug 2023 08:46:29 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> 31.05.2023 14:08, Jonathan Cameron via wrote:
> > On Wed, 31 May 2023 09:51:43 +0200
> > Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> >   
> >> On 31/5/23 08:07, Li Zhijian wrote:  
> >>> Allocate targets and targets[n] resources when all sanity checks are
> >>> passed to avoid memory leaks.
> >>>
> >>> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> >>> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> >>> ---
> >>> V3: allocte further resource when we can't fail # Philippe  
> >>
> >> Thanks for the v3!
> >>
> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>  
> > 
> > Thanks.  I've added this near the top of my queue so will send
> > it out along with other similar fixes as a series for Michael
> > to consider picking up.  
> 
> Hi!
> 
> Has this been forgotten? Is it still needed?
> 
> /mjt
> 

Sorry, I'm running a bit behind.  Have this one a few other fixes
still queued up - I didn't consider any of them particularly critical
for the release so wasn't rushing.

I'll aim to get them out as a series soon though so they are
available for start of next cycle if not for slipping in before
the release.

Jonathan
Michael Tokarev Sept. 8, 2023, 5:02 p.m. UTC | #5
08.08.2023 17:44, Jonathan Cameron:

> Sorry, I'm running a bit behind.  Have this one a few other fixes
> still queued up - I didn't consider any of them particularly critical
> for the release so wasn't rushing.
> 
> I'll aim to get them out as a series soon though so they are
> available for start of next cycle if not for slipping in before
> the release.

A month later, friendly ping? :)
(this is sent to -stable too, fwiw).

/mjt
Jonathan Cameron Sept. 11, 2023, 9:18 a.m. UTC | #6
On Fri, 8 Sep 2023 20:02:41 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> 08.08.2023 17:44, Jonathan Cameron:
> 
> > Sorry, I'm running a bit behind.  Have this one a few other fixes
> > still queued up - I didn't consider any of them particularly critical
> > for the release so wasn't rushing.
> > 
> > I'll aim to get them out as a series soon though so they are
> > available for start of next cycle if not for slipping in before
> > the release.  
> 
> A month later, friendly ping? :)
> (this is sent to -stable too, fwiw).

https://lore.kernel.org/qemu-devel/20230904132806.6094-2-Jonathan.Cameron@huawei.com/

Posted a series with this in last week.  Hopefully Michael will queue this
in his next pull.

Jonathan
> 
> /mjt
> 
>
diff mbox series

Patch

diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c
index 034c7805b3e..f0920da956d 100644
--- a/hw/cxl/cxl-host.c
+++ b/hw/cxl/cxl-host.c
@@ -39,12 +39,6 @@  static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         return;
     }
 
-    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
-    for (i = 0, target = object->targets; target; i++, target = target->next) {
-        /* This link cannot be resolved yet, so stash the name for now */
-        fw->targets[i] = g_strdup(target->value);
-    }
-
     if (object->size % (256 * MiB)) {
         error_setg(errp,
                    "Size of a CXL fixed memory window must be a multiple of 256MiB");
@@ -64,6 +58,12 @@  static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         fw->enc_int_gran = 0;
     }
 
+    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
+    for (i = 0, target = object->targets; target; i++, target = target->next) {
+        /* This link cannot be resolved yet, so stash the name for now */
+        fw->targets[i] = g_strdup(target->value);
+    }
+
     cxl_state->fixed_windows = g_list_append(cxl_state->fixed_windows,
                                              g_steal_pointer(&fw));