From patchwork Tue Oct 20 07:44:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 1384686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=lmichel.fr Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=lmichel.fr header.i=@lmichel.fr header.a=rsa-sha256 header.s=pharaoh header.b=PEREai9y; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CFlxs1xblz9sPB for ; Tue, 20 Oct 2020 18:44:17 +1100 (AEDT) Received: from localhost ([::1]:50556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUmJb-0003Ox-8d for incoming@patchwork.ozlabs.org; Tue, 20 Oct 2020 03:44:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUmJ2-0003Ns-Ph for qemu-devel@nongnu.org; Tue, 20 Oct 2020 03:43:40 -0400 Received: from pharaoh.lmichel.fr ([149.202.28.74]:56086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUmJ0-0008MW-O5 for qemu-devel@nongnu.org; Tue, 20 Oct 2020 03:43:40 -0400 Received: from sekoia-pc.home.lmichel.fr (sekoia-pc.home.lmichel.fr [192.168.61.100]) by pharaoh.lmichel.fr (Postfix) with ESMTPS id 1F895C60010; Tue, 20 Oct 2020 07:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lmichel.fr; s=pharaoh; t=1603179814; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=mlIRwhaHDHPVIU5gr1CK/VGLAMYhpYmFtsI2zoTsscE=; b=PEREai9yOngZf1GqKDJOEWjrdJaeX99Uer+pHaXjHCDv2TaPk5UmbUmA/O4tGsXF5pPzTC NHqqmlEHzKQLrG5N4fJqjSKE91WuOWluBpnuRLogbkqU2TnuJKWYhOT+vWzkLIna5gewM7 rcbej0puib9BcQJdid/wjf672RAc9+lqHz7XEO7RpAxorZ9s2hUlywQNo5VG4jkAKVQAkt gh9dSNlRchzltwiEgULN/BIEMsZHnE/DZp/3TIFCdgczXo5y08u7yTpDhR+p3Mf6uNLSfF 1fQ0Z/mFx7kUIr86HAl3WQl2Ez4zUq9U1wbofs+VZCrYS4LwXgOs5MH96TJiUA== From: Luc Michel To: qemu-devel@nongnu.org Subject: [PATCH] hw/core/qdev-clock: add a reference on aliased clocks Date: Tue, 20 Oct 2020 09:44:26 +0200 Message-Id: <20201020074426.105878-1-luc@lmichel.fr> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lmichel.fr; s=pharaoh; t=1603179814; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=mlIRwhaHDHPVIU5gr1CK/VGLAMYhpYmFtsI2zoTsscE=; b=Yarvetic0tbpnqTec95tfzSiysB7MwOlSiiGYESqICGoxtPWHTwdKr7PX/5zfwrv9q40U6 wtIfbvo+ach0MvciQvXwWlIA2mLmaQvF3ESjTg/ZpLfr0l7py8F3UIFsrSO7tWPpGdDIJb kISD56myzRwAoLsVxbhNx+L646+QSlONy2nErc+/zCPBVza7xkVZGOErKLZIau6ECZXw+U du4KXrvCNeVEQkH5uCQvg6crzPsJ8B+yrUZJhn1IPnxrMaodhNYrZFJr6VRozl30RXLz7e y6WbnABAOjGRw+m77QuGCRTEVYDHTylZO+dq4Mq/kVFX2Ml5Sn6m6+5Ug1A7kg== ARC-Seal: i=1; s=pharaoh; d=lmichel.fr; t=1603179814; a=rsa-sha256; cv=none; b=Gv2fTUD+di0dzPaEeafCOf2PettbxhyZhNUnZ85FH5ChIR04b2hqk6U+9a6IvEl1f7v1+SY97ePgHyK5DNcJQbmZAiZ3MI/zQPzojfeO+SmHtSLye4pWNY4lwqzKS6IUNm8T/KUbopW2+S6n3KC5M9HzLfSLBDdHGe8u8eQhh3c39qmOheyJrLxlwbgNpuEu0FfmiatpGxZ3xqlk+wq5vcVd3zL9ceHAwvMkMpVgALxHA6YbvlD7uUKHJdv0haSC5SbKCPRjWm4L/YAJD4qb3/Wa8L1JZ4BULAKp6zuwJnluQ6SjbJmg1R3G//Tt4J9gKyfEOxl96HVcvCd2ZjNjkQ== ARC-Authentication-Results: i=1; pharaoh.lmichel.fr Received-SPF: pass client-ip=149.202.28.74; envelope-from=luc@lmichel.fr; helo=pharaoh.lmichel.fr X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/20 03:43:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Damien Hedde , Peter Maydell , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?q?=C3=A9?= , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Paolo Bonzini , Luc Michel Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When aliasing a clock with the qdev_alias_clock() function, a new link property is created on the device aliasing the clock. The link points to the aliased clock and use the OBJ_PROP_LINK_STRONG flag. This property is read only since it does not provide a check callback for modifications. The object_property_add_link() documentation stats that with OBJ_PROP_LINK_STRONG properties, the linked object reference count get decremented when the property is deleted. But it is _not_ incremented on creation (object_property_add_link() does not actually know the link). This commit increments the reference count on the aliased clock to ensure the aliased clock stays alive during the property lifetime, and to avoid a double-free memory error when the property get deleted. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- hw/core/qdev-clock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 6a9a340d0f..5f5e143702 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -59,10 +59,11 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name, } else { object_property_add_link(OBJECT(dev), name, object_get_typename(OBJECT(clk)), (Object **) &ncl->clock, NULL, OBJ_PROP_LINK_STRONG); + object_ref(OBJECT(clk)); } ncl->clock = clk; QLIST_INSERT_HEAD(&dev->clocks, ncl, node);