From nobody Thu Dec 26 21:36:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1732903483; cv=none; d=zohomail.com; s=zohoarc; b=iMAUaq0ytVoGDPZyCbDiM4zbw7MsiKZ1Aw+e7e7nPiZ75fTFfk6CKlMy1GgxexHI39vOlfV/S0xJsvdWaZ5dUzDXYGJ7TKorosBoiRWXhJMJg8M95XUFbU4/hwGbUTq3CBrvvcngmXo9x9St4gWVvftUCacxcx7DrinN4kQa6JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732903483; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ojufsuB566tnZ5C6giuV7h4t8CKcRsp0Kt6yZG9sXHw=; b=ftmsff8idr9tUlI3OSgmLKq4Jel5lgV7Xar9NG8qdN9A6R6/qU4QpkkSqCO63lXEs9OPwaf4mFGaCOdkQKzEFyP/uQxiSXqm3SQNDnmwsOQHi+tc9iNJaHc11xYI0WACDmvw57zHE3o8NWxbWni3Xx4jurbQy2AdMaJj7ah77KA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732903483772217.97172591749688; Fri, 29 Nov 2024 10:04:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH5LB-00041l-E9; Fri, 29 Nov 2024 13:03:41 -0500 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 1tH5L6-000417-TL for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH5L5-0006NF-FR for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:36 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-U5oLiCWPM1yGz7Fg7JOSHg-1; Fri, 29 Nov 2024 13:03:32 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa5449e1d9cso132041366b.2 for ; Fri, 29 Nov 2024 10:03:32 -0800 (PST) Received: from [192.168.1.84] ([93.56.170.251]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5997ff0d5sm194080466b.85.2024.11.29.10.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 10:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732903414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojufsuB566tnZ5C6giuV7h4t8CKcRsp0Kt6yZG9sXHw=; b=WKykog2cHAff7ELF0NHQoQOENO1rb9C1jBxCOEKy8Lgm2YRFq3edXj6VGPxpYquTHy7S3F FCapG8DJnPXqjHb0TipycmoOvfllZjCQC2UGRKT8Mz1BEqlYVCIT0oRbpM74xGuULEu9UM CmpHFqceR9ie21vA1tYe+Ch1Gl2wDLU= X-MC-Unique: U5oLiCWPM1yGz7Fg7JOSHg-1 X-Mimecast-MFC-AGG-ID: U5oLiCWPM1yGz7Fg7JOSHg X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732903411; x=1733508211; 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=ojufsuB566tnZ5C6giuV7h4t8CKcRsp0Kt6yZG9sXHw=; b=An1wzd/PQwt2Ggsc2MrreqnCUeWOidId6JQTDOZ7QzB02dLn/wPLF1YIeKmtG8lIvX XBpabUgM0phkq0UDidj778rYRW4SJIEStIyaBDcZydhPFdZMKFr8E3TrbrClsmBYdOhp MERnrCpx6lMuAwudtYqQ5DClGtxgHSU9tPZx94y2t29VgY9Ep0uBMgVfHTiH10Z27KEo q1YGJfHbMuelpJ/SxKypZmDxWQHX0RDZ5pBGMt5tHpwWDwJjtEq5YUViBD9CIGxgbQWu 4CPd0fHlb1I/murgGYmbGj9aCyI+S0apI2F9zrtNY8J/WvWrnvVt5eMOmFFUxAQTrZJH +DGw== X-Gm-Message-State: AOJu0Yx+VqM2S5bzbCNWnmqB2lN7kUSjJCxZ4+EYiTTOX9e6Ys8E/9IB zfeUlyRRH7N87IriZ55WRCU9YjU9zUxtdv19tlHS96Im31TiNCRBO35UuhfXFNoN0dKJwnU97OD tc22M76JOcst40RbRprnFnzS3Zf/QfcDyxRZqC7wTlHsNlC56PHISoz1If3J4lfm2TTibqMJIMP DHXRi8u85aHoyJF47xqlVoLgfQGbK3YVCXM6Uo X-Gm-Gg: ASbGncuFD5fEL8eYQaP89LufPpgft/lL+irmwsSkhYdmXfREzcwAdF/KG8bWWa1A0rA 6FJpFQZBsSgyIqUOv8/dYUM3e/Nghv5tUuWMxETGOw9kNgMTMfFRpvv4Y77LQLEYBRZWc2aPqNJ hQt0IQyGNBcf/O3g4HOuEXQzPgaS0dBhoqArSIvZLrHcU8Pty0TAB99IfxOQifnbozpc9HZ+uJn SC1X85SuMqCTvFzNahWZR6pPvwbLYV7T+47qdx3ciKdchzx4WOF X-Received: by 2002:a17:907:93c1:b0:aa4:ce81:6d92 with SMTP id a640c23a62f3a-aa5810559abmr993052866b.38.1732903410946; Fri, 29 Nov 2024 10:03:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcaH98g/aKOXkcSAzeimGrYvz9gdVa/ULmk9tzYCDKi+YAb46/bKejxaa6n1dzchG/qIy62A== X-Received: by 2002:a17:907:93c1:b0:aa4:ce81:6d92 with SMTP id a640c23a62f3a-aa5810559abmr993043966b.38.1732903410235; Fri, 29 Nov 2024 10:03:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: philmd@linaro.org Subject: [PATCH 1/3] clock: clear callback on unparent Date: Fri, 29 Nov 2024 19:03:24 +0100 Message-ID: <20241129180326.722436-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129180326.722436-1-pbonzini@redhat.com> References: <20241129180326.722436-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1732903485308019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- include/hw/clock.h | 8 -------- hw/core/clock.c | 22 +++++++++++++++++----- hw/core/qdev-clock.c | 5 +---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/hw/clock.h b/include/hw/clock.h index eb58599131c..a279bd4ba5e 100644 --- a/include/hw/clock.h +++ b/include/hw/clock.h @@ -141,14 +141,6 @@ Clock *clock_new(Object *parent, const char *name); void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque, unsigned int events); =20 -/** - * clock_clear_callback: - * @clk: the clock to delete the callback from - * - * Unregister the callback registered with clock_set_callback. - */ -void clock_clear_callback(Clock *clk); - /** * clock_set_source: * @clk: the clock. diff --git a/hw/core/clock.c b/hw/core/clock.c index cbe7b1bc469..391095eb4e5 100644 --- a/hw/core/clock.c +++ b/hw/core/clock.c @@ -44,16 +44,12 @@ Clock *clock_new(Object *parent, const char *name) void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque, unsigned int events) { + assert(OBJECT(clk)->parent); clk->callback =3D cb; clk->callback_opaque =3D opaque; clk->callback_events =3D events; } =20 -void clock_clear_callback(Clock *clk) -{ - clock_set_callback(clk, NULL, NULL, 0); -} - bool clock_set(Clock *clk, uint64_t period) { if (clk->period =3D=3D period) { @@ -168,6 +164,16 @@ static void clock_period_prop_get(Object *obj, Visitor= *v, const char *name, visit_type_uint64(v, name, &period, errp); } =20 +static void clock_unparent(Object *obj) +{ + /* + * Callback are registered by the parent, which might die anytime after + * it's unparented the children. Avoid having a callback to a deleted + * object in case the clock is still referenced somewhere else (eg: by + * a clock output). + */ + clock_set_callback(CLOCK(obj), NULL, NULL, 0); +} =20 static void clock_initfn(Object *obj) { @@ -200,11 +206,17 @@ static void clock_finalizefn(Object *obj) g_free(clk->canonical_path); } =20 +static void clock_class_init(ObjectClass *klass, void *data) +{ + klass->unparent =3D clock_unparent; +} + static const TypeInfo clock_info =3D { .name =3D TYPE_CLOCK, .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(Clock), .instance_init =3D clock_initfn, + .class_init =3D clock_class_init, .instance_finalize =3D clock_finalizefn, }; =20 diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 82799577f3e..ca65685c04e 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -87,11 +87,8 @@ void qdev_finalize_clocklist(DeviceState *dev) if (!ncl->output && !ncl->alias) { /* * We kept a reference on the input clock to ensure it lives u= p to - * this point so we can safely remove the callback. - * It avoids having a callback to a deleted object if ncl->clo= ck - * is still referenced somewhere else (eg: by a clock output). + * this point; it is used by the monitor to show the frequency. */ - clock_clear_callback(ncl->clock); object_unref(OBJECT(ncl->clock)); } g_free(ncl->name); --=20 2.47.0 From nobody Thu Dec 26 21:36:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1732903473; cv=none; d=zohomail.com; s=zohoarc; b=H/hGjqlbia8pOVhAdBJb43AbFPeYjEi5GanKKZWNPZeCRiMSCnQkVIhEGMLkUOZz5/X8Toz4PG20YzkUtCwxTauwNSB3T7XGH73m3njRKE6/4Wlsjgla1MTUlpAD7ZIy+m+/7VdVrOp6UguKX1M4YLDCokgqYLmoAfORIIOsyyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732903473; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P+U9ukd1FP1SXGWD1ZHLvvkFx0WIB0UvvucvkGaKpj0=; b=Knnv+NXXwXYZ9EypQ/Svc2dhuZkNFIRcIrWGhngFQe6pNhOhRtBB+pQHSdnHK3d7YBSjMjNLnkKxAet/nrfzvnNzF1u8tMi48oKhwqXhHJdmF3MboaG+a7GWqrxp6BpGfBLNA+n0k/MhtcfPLx3qwsy0dfztro3ll4Z1+mwAz18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732903473456611.9237102331621; Fri, 29 Nov 2024 10:04:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH5LE-00042M-Gc; Fri, 29 Nov 2024 13:03:44 -0500 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 1tH5LA-00041M-8m for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH5L6-0006Nd-VP for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:38 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-20iGsUloMLeRMlvFMfVq8w-1; Fri, 29 Nov 2024 13:03:34 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa53efda0f2so115181466b.0 for ; Fri, 29 Nov 2024 10:03:33 -0800 (PST) Received: from [192.168.1.84] ([93.56.170.251]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa59991f11esm195102866b.167.2024.11.29.10.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 10:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732903415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+U9ukd1FP1SXGWD1ZHLvvkFx0WIB0UvvucvkGaKpj0=; b=S+Lfgh7fefHW9j9e7XsHaZZSBNAwonbfUaqlWMXmQwUnwhSje1ZQd12x0H/ZyJ0fyU8ylA 52cY4FsgJKV7aDpDcgH9ZSdq94M420RpejttGPmU6oMwUs2PtHv5YIBuy/o2weuNqrS6G4 9sHecPjB3KlTGNwOgNQnlNmKNnU4P+s= X-MC-Unique: 20iGsUloMLeRMlvFMfVq8w-1 X-Mimecast-MFC-AGG-ID: 20iGsUloMLeRMlvFMfVq8w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732903412; x=1733508212; 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=P+U9ukd1FP1SXGWD1ZHLvvkFx0WIB0UvvucvkGaKpj0=; b=ffEDuIm9q/soiSmP3KjX1avSs6/ShHmIiDkhvBpB/SyFGApSPRydpqbXOnwUlPrHGV 7NEh/rbkFw+JiCBLwlxv9WiCYUS8fNaqIC3fkilu1Sbz2be/zs28hCqpnyGnz2knUQ+B t284qKKvAl/cwC/aHFc177r8hYheuGyyI0a/dLiQ4rKrrCEIgqIh1tAGeOzzK7iDi/3c lRp23QPv3WC5ZKigqRlfjtT0t80h6ZwIBw0dCS6vM/PAjBXjzE5ON9hBYjx/1T1jcfV1 ft0OfiOSIUf3lWOzQKtHyA93Yk3PvSe3EKU0A2140HjMZyBxarzrlFCgo+YEsGd3QdOE JcHw== X-Gm-Message-State: AOJu0Yz6wYP9ROJ7EtjDaeFCEVdhw4tS2AjzUr8KjWyGjKhDX3oIrBO0 Ma909xPqNP86aEWb/V6aGHMIOZBfRjkJ4kX1bUVelxvQvUU41lZG9u6btnL1yYsSuqFCg+16EES YTSj4SzSmBMzDpHDKknzQWeTG6FhQRKw9QkBGruLdCh/Ag2QG4XOLoSpeO4Oi34BTyb+er963ai hbpbCUkObsm1WiRarPh5FaSRj9LTTFy1uKOuLy X-Gm-Gg: ASbGncuqENZzPfLLQ+ytg7nm8wRTE6e32wy7ZXoi8RauWhSBeJK8YdYgLRanXD0KyF4 eg1NExxNO59TVJ84OuzKmgszpUr9JvQgRUi2guh42hUgsFzAgpH9WsP1Yu1O27RdSkEan/8ynJx 1OBSsmJFFkw6yNY6TIy0VQTqsRwMRZPQUDGgSA9Lt/We47sM7Wz8s4BGjcdQP5vwfmqBNDO0KhF F4H4FfejIDFtFgMUmLJjLLBJ9+fz2HNB0PwT/iBam2MTGztDWbK X-Received: by 2002:a17:907:7713:b0:aa5:cec:d504 with SMTP id a640c23a62f3a-aa580f57d8dmr1074789666b.30.1732903412199; Fri, 29 Nov 2024 10:03:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDGHw/8+ZtYjcDoc7KD3M8QCI+Bk8N3Ke7YEmXxzfX2CNS7RBXUM6Okh2GEibMBE0h+qdQUQ== X-Received: by 2002:a17:907:7713:b0:aa5:cec:d504 with SMTP id a640c23a62f3a-aa580f57d8dmr1074780866b.30.1732903411535; Fri, 29 Nov 2024 10:03:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: philmd@linaro.org Subject: [PATCH 2/3] clock: treat outputs and inputs the same in NamedClockList Date: Fri, 29 Nov 2024 19:03:25 +0100 Message-ID: <20241129180326.722436-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129180326.722436-1-pbonzini@redhat.com> References: <20241129180326.722436-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1732903475298019100 Content-Type: text/plain; charset="utf-8" Leave around a reference not just for inputs but also for outputs. This is a better choice because in principle the monitor could walk the NamedClockList after the clocks have been unparented (which would free them) and before qdev_finalize_clocklist(). Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/qdev-clock.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index ca65685c04e..2f9d6cb7579 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -48,14 +48,6 @@ static NamedClockList *qdev_init_clocklist(DeviceState *= dev, const char *name, if (clk =3D=3D NULL) { clk =3D CLOCK(object_new(TYPE_CLOCK)); object_property_add_child(OBJECT(dev), name, OBJECT(clk)); - if (output) { - /* - * Remove object_new()'s initial reference. - * Note that for inputs, the reference created by object_new() - * will be deleted in qdev_finalize_clocklist(). - */ - object_unref(OBJECT(clk)); - } } else { object_property_add_link(OBJECT(dev), name, object_get_typename(OBJECT(clk)), @@ -84,7 +76,7 @@ void qdev_finalize_clocklist(DeviceState *dev) =20 QLIST_FOREACH_SAFE(ncl, &dev->clocks, node, ncl_next) { QLIST_REMOVE(ncl, node); - if (!ncl->output && !ncl->alias) { + if (!ncl->alias) { /* * We kept a reference on the input clock to ensure it lives u= p to * this point; it is used by the monitor to show the frequency. --=20 2.47.0 From nobody Thu Dec 26 21:36:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1732903472; cv=none; d=zohomail.com; s=zohoarc; b=nTfO/kmVKuSMU9HiSYTcgJMqbSOa9rLg+4/2wvKcVe421CgHP8iLFUVYF1rUnGoea1p7G4wd/nc+IoZC5SQR3J+czzgBkzresLWRzuja9phRrdNFvI4JV725cTtDEcX6DtXRGC1g4zqjqRSWWknVoZ8y4V43Mee+UMI+gz5+WIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732903472; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QElT273DCPwXRmjrILbj0xzrSJsB2liod7ICaJaBk+8=; b=Kn63D3vhgMEhW0PMS1thp5faQr0hxySxEukbz8hrX3ggi3LnUHw6JNiw1XybShXIAsd6pep6tMSXCJi3Ax71TP+AEKYi32w9dzas5egUQ8BfwurFzclzrUNQYyAbZlVMFYPzeSLrpZv29ygFyinXgCeLzFkGEIpsYRH88bAFG6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732903472164216.48454418063568; Fri, 29 Nov 2024 10:04:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH5LN-00042Q-E1; Fri, 29 Nov 2024 13:03:57 -0500 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 1tH5LC-000426-8x for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH5LA-0006OZ-LB for qemu-devel@nongnu.org; Fri, 29 Nov 2024 13:03:42 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-ScJAr475NBK924dJ04u8NA-1; Fri, 29 Nov 2024 13:03:36 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aa527da110bso131471966b.0 for ; Fri, 29 Nov 2024 10:03:35 -0800 (PST) Received: from [192.168.1.84] ([93.56.170.251]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa59990a848sm196381366b.150.2024.11.29.10.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 10:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732903420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QElT273DCPwXRmjrILbj0xzrSJsB2liod7ICaJaBk+8=; b=bcKgemqiUaD70az41/xsUNXsJ0vm5ePoaGvBs/1itZtxjcuFFolbCMJJ8JYBbqGxivW+9v i0FS0/GkTx/tAJKF6pwnVXc7UMfg0QZHocXaHC3pM/2CZS7IIJNmsubHJy/h+4gAfNJADL 3Oc+AdO01cb06KBEUzWGs0n1UGDgljU= X-MC-Unique: ScJAr475NBK924dJ04u8NA-1 X-Mimecast-MFC-AGG-ID: ScJAr475NBK924dJ04u8NA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732903414; x=1733508214; 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=QElT273DCPwXRmjrILbj0xzrSJsB2liod7ICaJaBk+8=; b=iI1hHu+pP0k49txsuFIUsktzviJbjcVCDM/CMSwZraa2alGEQnBarwNrBj24TXJNkh yhE1HmR138BlIbI0EtJuPPrtDBaeg7TxWHF8kZ+8vIeQWmykVc8voeMYQNlBxV7hHODE DnSZd0a44Shy607JbdWn6oTcZunY8KdaeXicnlyqr4siml5vSZA7WGiE51IUD2LPXvVz GVHGL9emkHYLqHxlexye01Ds397qLhdHwwFmoPjyKv0+rE6UFe+ZEDeKdzm6UQB6lGV7 l/DfRgcZP5vPmH31OND3/YSoaKaoMKQyKwvx8N8ZKFl68e1hAhyUVU0OJrbqFNYVWkbc 244Q== X-Gm-Message-State: AOJu0Yz700wzkD9sLDtbcHu8597rcpsXPhgM3HtC+DudSF9y32TtbhmD z85GHpJ791MFfTL95MY19AbaQGVYOFjZ4i68R6srVLul0mjX/hGVfh7ImRtW5CTA7heUBWmNI6u eb+bLfiAH5sTnt0f9xww/sv+WZZZEgSIWq7sPA6O8k1DjrwkMNPxvbF1wWxYqv+x12/6XbQYPRJ sZ20KSCn0uBPQlO/Kj/aVkDc9q5CDj+fdc7tXo X-Gm-Gg: ASbGncsJZYzQY2/whxI3PM2N2yeNt1bG/lHjnmcI2zqCrzl387lFJ5+dTUZiFXSB96I 3qDn7R4mrlCFY2CMlihfx8YxWDXFOEYsIsrH/pMdM5zgRi6dA34+IfL+ayDCuDNOqSohwW+w2Td Ya1/SjUP6PbOcBPGKFeeMrk1I6+lIHdHzyIuE65pCQ72DWZluqf7ypggJy/kjnjTFtSV1mJ7Rds ewxqBVZPr+mSX2ca/c6093zjfsDRR3w7jhpvCEuVM9pLeGq27DB X-Received: by 2002:a17:906:3ca2:b0:aa5:2bfb:2ebf with SMTP id a640c23a62f3a-aa580f2c485mr898888266b.22.1732903413519; Fri, 29 Nov 2024 10:03:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYoINRlNeoOxUWMtthfFak97YYyLol5Ov189AJr8YQFCv6Z4XuHwT63wbuqpnSAmJIuoIfWQ== X-Received: by 2002:a17:906:3ca2:b0:aa5:2bfb:2ebf with SMTP id a640c23a62f3a-aa580f2c485mr898881966b.22.1732903412887; Fri, 29 Nov 2024 10:03:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: philmd@linaro.org Subject: [PATCH 3/3] clock: inline most of qdev_init_clocklist Date: Fri, 29 Nov 2024 19:03:26 +0100 Message-ID: <20241129180326.722436-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129180326.722436-1-pbonzini@redhat.com> References: <20241129180326.722436-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.93, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1732903473695019100 Content-Type: text/plain; charset="utf-8" Move object creation out of qdev_init_clocklist. The input/output cases are very simple, and the aliases are completely different. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/qdev-clock.c | 71 +++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 2f9d6cb7579..dacafa4e036 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -22,7 +22,7 @@ * Add a new clock in a device */ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *n= ame, - bool output, Clock *clk) + bool alias, bool output, Clock = *clk) { NamedClockList *ncl; =20 @@ -38,31 +38,8 @@ static NamedClockList *qdev_init_clocklist(DeviceState *= dev, const char *name, */ ncl =3D g_new0(NamedClockList, 1); ncl->name =3D g_strdup(name); + ncl->alias =3D alias; ncl->output =3D output; - ncl->alias =3D (clk !=3D NULL); - - /* - * Trying to create a clock whose name clashes with some other - * clock or property is a bug in the caller and we will abort(). - */ - if (clk =3D=3D NULL) { - clk =3D CLOCK(object_new(TYPE_CLOCK)); - object_property_add_child(OBJECT(dev), name, OBJECT(clk)); - } else { - object_property_add_link(OBJECT(dev), name, - object_get_typename(OBJECT(clk)), - (Object **) &ncl->clock, - NULL, OBJ_PROP_LINK_STRONG); - /* - * Since the link property has the OBJ_PROP_LINK_STRONG flag, the = clk - * object reference count gets decremented on property deletion. - * However object_property_add_link does not increment it since it - * doesn't know the linked object. Increment it here to ensure the - * aliased clock stays alive during this device life-time. - */ - object_ref(OBJECT(clk)); - } - ncl->clock =3D clk; =20 QLIST_INSERT_HEAD(&dev->clocks, ncl, node); @@ -90,29 +67,25 @@ void qdev_finalize_clocklist(DeviceState *dev) =20 Clock *qdev_init_clock_out(DeviceState *dev, const char *name) { - NamedClockList *ncl; + Clock *clk =3D CLOCK(object_new(TYPE_CLOCK)); + object_property_add_child(OBJECT(dev), name, OBJECT(clk)); =20 - assert(name); - - ncl =3D qdev_init_clocklist(dev, name, true, NULL); - - return ncl->clock; + qdev_init_clocklist(dev, name, false, true, clk); + return clk; } =20 Clock *qdev_init_clock_in(DeviceState *dev, const char *name, ClockCallback *callback, void *opaque, unsigned int events) { - NamedClockList *ncl; - - assert(name); - - ncl =3D qdev_init_clocklist(dev, name, false, NULL); + Clock *clk =3D CLOCK(object_new(TYPE_CLOCK)); + object_property_add_child(OBJECT(dev), name, OBJECT(clk)); =20 + qdev_init_clocklist(dev, name, false, false, clk); if (callback) { - clock_set_callback(ncl->clock, callback, opaque, events); + clock_set_callback(clk, callback, opaque, events); } - return ncl->clock; + return clk; } =20 void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks) @@ -183,15 +156,25 @@ Clock *qdev_get_clock_out(DeviceState *dev, const cha= r *name) Clock *qdev_alias_clock(DeviceState *dev, const char *name, DeviceState *alias_dev, const char *alias_name) { - NamedClockList *ncl; + NamedClockList *ncl =3D qdev_get_clocklist(dev, name); + Clock *clk =3D ncl->clock; =20 - assert(name && alias_name); + ncl =3D qdev_init_clocklist(alias_dev, alias_name, true, ncl->output, = clk); =20 - ncl =3D qdev_get_clocklist(dev, name); + object_property_add_link(OBJECT(alias_dev), alias_name, + TYPE_CLOCK, + (Object **) &ncl->clock, + NULL, OBJ_PROP_LINK_STRONG); + /* + * Since the link property has the OBJ_PROP_LINK_STRONG flag, the clk + * object reference count gets decremented on property deletion. + * However object_property_add_link does not increment it since it + * doesn't know the linked object. Increment it here to ensure the + * aliased clock stays alive during this device life-time. + */ + object_ref(OBJECT(clk)); =20 - qdev_init_clocklist(alias_dev, alias_name, ncl->output, ncl->clock); - - return ncl->clock; + return clk; } =20 void qdev_connect_clock_in(DeviceState *dev, const char *name, Clock *sour= ce) --=20 2.47.0