From patchwork Thu Aug 22 16:21:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 821334 Delivered-To: patch@linaro.org Received: by 2002:adf:e98a:0:b0:367:895a:4699 with SMTP id h10csp1268387wrm; Thu, 22 Aug 2024 09:22:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUwEjRPrfCKqgoaz5+3wGGvrcCGuRrLDpNb+xF7jNWnKSqdiKMlkmcyXhhtCbhqy6QQ17fDww==@linaro.org X-Google-Smtp-Source: AGHT+IGDm4tSIDD8MTFErkwmCODRol7msDXaWcJEWKerPwapxdfcmJpkpNSUmAwo6B3CzI3LvH8n X-Received: by 2002:a05:6358:7252:b0:1aa:c71e:2b4d with SMTP id e5c5f4694b2df-1b5b3a91332mr277903055d.20.1724343779513; Thu, 22 Aug 2024 09:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724343779; cv=none; d=google.com; s=arc-20160816; b=RUS/q0HBqgYD4g80jSTY0B2xNf3hhXskEXD7xME6ASlODdXBxtT/xdU8sK0X0AClUM InwMqBcgaXRBr64BcDyv/XCzw2CCXmx4ldc7yMkFygsDo1RG8YfNV4d/wht9tb+eD+24 YWmBJm1048YZrICa3PWNRmiEcL0eGYnJ0nYzGkaB6uGYT5dW8LKyNptvckX2QS8ira4E pDIWydPsvNUq5nz8DI7w9lD/UuG3JZEpKUam8B2OKDhJwbci+XP9GWlCLl7ZcTyEZZ44 nMNkUNDKekPnhYvxqNIeCy3BZfsshDTBOHEG8klCoTZ6thLvfykQyuE9SVV8QJTD3MBn /F7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rRIh29OU7dNzm5XtXlrEQk7GPVofTkxU59XhpGGv5/A=; fh=hsiZh6z6VL+K4CvpaUQuXHcVxoA2TLjwNmkcb4IzG1o=; b=CTJSyv963t/yV4zfo11miObMgUcfq/r2eAO5ce5boDnY57TriLWxbhZHLO1FQzR1Ts TN1AMQpEQh7+aSVPgd8wgfn6YagnlwIR9Yxw6lzKP18tQ1J92K/xQM2H3w63NJjFr5I7 kCvH6bP8pvgHZJ0HG9X1aMS9a0RvJD5m9vIuTSSHaCyD4V2LY44Tk264N5Dm2Zux9BHU 5TPdrK+a8+bsblZfZ9ZmvRuLaoDayQzToZvQLKdmjoI1r2VH+zaaRuxB2BTnRB0O6kuK Sg+cnnUJnndc3ZlByxl83iMUfgI1Ip3ZSE3+urZlD8hYAyEF7mhkKK7BBDdvx33d+edH YAGg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aqig05m1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 71dfb90a1353d-4fd0832d05csi485964e0c.156.2024.08.22.09.22.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Aug 2024 09:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aqig05m1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1shAZN-0005id-3M; Thu, 22 Aug 2024 12:21:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1shAZD-000575-FW for qemu-devel@nongnu.org; Thu, 22 Aug 2024 12:21:43 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1shAZ4-0007K9-5m for qemu-devel@nongnu.org; Thu, 22 Aug 2024 12:21:38 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42816ca782dso7484165e9.2 for ; Thu, 22 Aug 2024 09:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724343690; x=1724948490; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rRIh29OU7dNzm5XtXlrEQk7GPVofTkxU59XhpGGv5/A=; b=Aqig05m1LszCefa1p+WpMvLPgGz1e5vPghRll6xMHoUz/EcDSOHpEkHL5YXl0DWz8J lAvmMzzQHJw1xwV+nNoLXBZfFPcgwo54r24WYpH8HDvqMvobF61/5k76TlqueBfGeQoe vJ70y2R6GY0vN1Vx20sKPMKbq2j83IpZUWTa6LrJl2YKEb4zB9pGb26JHprUu2gnpsEQ 5PhTGKwFsn3Ltb4i/IZy5vzeRq94dMZ332SqXE6T6IuOdAVBT/VMriwg8qD/zxDdeSMA NDAmiZZXX/XEm4i/GYR13oPTN4FIB+ZiYhc4CEaGHuyIum4q6Y+sA6lz8PJ5tKNHDAMU KwTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724343690; x=1724948490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rRIh29OU7dNzm5XtXlrEQk7GPVofTkxU59XhpGGv5/A=; b=UCDWTRi6pH/1Dy62WSMN+xlX1lY1jXoZAfcK5/9ROtMTAlAcmYbrPaAUZqlJii22nQ uv8whvY/XBPdym+CON/65PQtQRnbc7KM76lS4AHCClAWcAUU4eUM1nVzU1qfwxUoUAgM EU3sX2dVwxy1JdkUOmcjCneiZOmhYmUHJOlsRYUHjdPc4F1BPPRp/cP1HGxyziVjFO+0 pIDCuM/JU2YojnO+hEp54uyIYfQLweCbEfMv543UJmmxdy0z11EdqHLyyZVmfrG3ifc1 894bzwpnBUvNvYET9UGiL/KkSGux1b6MqFGTi9cSlFqaswL1CgJgSMtSee4YQymkPFSi gXdg== X-Forwarded-Encrypted: i=1; AJvYcCW3ol+XsMMDThZOzC2yxjQWfABilIVpaVZyRV7xrzHIE6DFCVS+Xvtijbq0DYpaVWCm0PArGeq4ixBS@nongnu.org X-Gm-Message-State: AOJu0Yxjjw5ADQkCGqqiPPvzNayvsdEJTgUD0vgxYO2elZR0Xc6DpMSy LUYdsxTYzVhyeWxGeR9al6Rweh0/cC31tGpIZFacZku5pJG4qMDw7ehEjg2y0qk= X-Received: by 2002:a05:600c:1992:b0:426:6ee7:c05a with SMTP id 5b1f17b1804b1-42abd23061amr43199385e9.15.1724343690325; Thu, 22 Aug 2024 09:21:30 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac5162347sm28928485e9.23.2024.08.22.09.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 09:21:30 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Alistair Francis , "Edgar E. Iglesias" , Francisco Iglesias Subject: [PATCH for-9.2 2/6] hw/misc/xlnx-versal-trng: Free s->prng in finalize, not unrealize Date: Thu, 22 Aug 2024 17:21:23 +0100 Message-Id: <20240822162127.705879-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240822162127.705879-1-peter.maydell@linaro.org> References: <20240822162127.705879-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The TYPE_XLNX_VERSAL_TRNG device creates s->prng with g_rand_new() in its init method, but it frees it in its unrealize method. This results in a leak in the QOM introspection "initialize-inspect-finalize" lifecycle: Direct leak of 2500 byte(s) in 1 object(s) allocated from: #0 0x55ec89eae9d8 in __interceptor_calloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/asan/qemu-system-aarch64+0x294d9d8) (BuildId: 6d5 08874816cc47d17c8dd775e8f809ae520e8cb) #1 0x7f697018fc50 in g_malloc0 debian/build/deb/../../../glib/gmem.c:161:13 #2 0x7f6970197738 in g_rand_new_with_seed_array debian/build/deb/../../../glib/grand.c:202:17 #3 0x7f6970197816 in g_rand_new debian/build/deb/../../../glib/grand.c:286:10 #4 0x55ec8aa3656a in trng_init hw/misc/xlnx-versal-trng.c:624:15 #5 0x55ec8ce75da1 in object_init_with_type qom/object.c:420:9 #6 0x55ec8ce5d07b in object_initialize_with_type qom/object.c:562:5 #7 0x55ec8ce5e91d in object_new_with_type qom/object.c:782:5 #8 0x55ec8ce5e9f1 in object_new qom/object.c:797:12 #9 0x55ec8d65c81d in qmp_device_list_properties qom/qom-qmp-cmds.c:144:11 Move the free to finalize so it matches where we are initing s->prng. Since that's the only thing our unrealize method was doing, this essentially switches the whole function to be a finalize implementation. Signed-off-by: Peter Maydell Reviewed-by: Alistair Francis --- hw/misc/xlnx-versal-trng.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/misc/xlnx-versal-trng.c b/hw/misc/xlnx-versal-trng.c index 51eb7600414..c0d1dde8708 100644 --- a/hw/misc/xlnx-versal-trng.c +++ b/hw/misc/xlnx-versal-trng.c @@ -624,9 +624,9 @@ static void trng_init(Object *obj) s->prng = g_rand_new(); } -static void trng_unrealize(DeviceState *dev) +static void trng_finalize(Object *obj) { - XlnxVersalTRng *s = XLNX_VERSAL_TRNG(dev); + XlnxVersalTRng *s = XLNX_VERSAL_TRNG(obj); g_rand_free(s->prng); s->prng = NULL; @@ -689,7 +689,6 @@ static void trng_class_init(ObjectClass *klass, void *data) ResettableClass *rc = RESETTABLE_CLASS(klass); dc->vmsd = &vmstate_trng; - dc->unrealize = trng_unrealize; rc->phases.hold = trng_reset_hold; /* Clone uint64 property with set allowed after realized */ @@ -706,6 +705,7 @@ static const TypeInfo trng_info = { .instance_size = sizeof(XlnxVersalTRng), .class_init = trng_class_init, .instance_init = trng_init, + .instance_finalize = trng_finalize, }; static void trng_register_types(void)