Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp484349lqi; Thu, 7 Mar 2024 03:12:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU3dEwgNWZkp5XHZuyFTvDWpEpy0qwsJWXFFIpchjcmNxNxG09p1Ep9j/h5uz89UXZsYesXdjSlyyP3k1ShOLJ09kkEnGk4myJnJTHOjA== X-Google-Smtp-Source: AGHT+IElwQjNgFLkjFgcDUARgk1upvOy+wwXEDTBDusV56bmH4Poo4uxiDz7YLO6E05owPpG0gH9 X-Received: by 2002:a17:906:b154:b0:a45:da1:9364 with SMTP id bt20-20020a170906b15400b00a450da19364mr8930660ejb.19.1709809924380; Thu, 07 Mar 2024 03:12:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709809924; cv=pass; d=google.com; s=arc-20160816; b=MC0/I2F6mP1TLMofQfr7oRgFHyNbt0N1LAHb5BeG2yRtl/QfRD1UGh5jvHEP+v1+KP FGGlqyomsDIs2hvEo8eu4UaPoZQHbNtz25v6G4wbf56URfE/7ztSa3/g/gcG1zG6gnk7 DA38BkD93RTDf7mP3g37y//1lODryaBOMOkBK0gb7R6V73crmihu4GLGCO7Y30vhsvYE loATXSG3xWsuOy2WXVKqsoH7HaGiUlalxEDzJ0RWrt0TmCN0ct1Nc7emQBm/X2NjOQcS 0SAa5psm34SOfIv6Prz3YMWp+oX6tOeurTLlZcuwNVQGD5/ADhxGDzqIU/2dvkMXpjNx kSlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OnOBH7X5Za0alGDnm8qdXNdP8bUSPL0B1vzgu9qjY6M=; fh=JfsClYTjt8qDhUqyVlL6sma6bIUBcmxkDWND1AnjMEI=; b=bycKlpY8no6WrzFTIVUQArE9eMbvzzJJ77wfibHu8un+xgML/kwKWig8fomHcWy86Z wE/ik6owuFtGgou73iu/RECXMFjNDbSkTYHyxjxkQz1JVtAoMSb48trIKhHAmdrMu5so aL/j9EkDrJD4YORKxVpl7gMKHjf21QJPnJbMqS1Ic2SSeFhKZUIlYREHhUDolEhgfnGB kjrlKXTKNPEBOhstVoTYhGjZzqRRCqjq1ywxE/2mWh/Yu519qRduHPmjCI7JpQIhUGW0 Df69Ae+nuKzNii1IFWlrLWLpCGaVmRqrJ7FXMEHBe3fSm9TTlKbpz2ZvLj/V4CB/+j7D MzSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Vpra+LW8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-95387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95387-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cw12-20020a170906478c00b00a45d6dcdfe4si330513ejc.563.2024.03.07.03.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 03:12:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Vpra+LW8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-95387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95387-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C6E2E1F2580D for ; Thu, 7 Mar 2024 11:11:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8FFE127B7E; Thu, 7 Mar 2024 11:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Vpra+LW8" Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9011129A62; Thu, 7 Mar 2024 11:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709809853; cv=none; b=cmKb/zner8kTMc0bw5uuzSGZZMjAVaHTBsC/VuNL9sf5DDE+dHKYS54zdfym7I+7kamM9tCSXrlr1+cbduaM+mKc1yaiKlgY9GUv2ICQgKvLyv1a6C5FQgKUc4mqDfZLbDLM1qC95zm5lehouz85LNS5UDfP3YEqG5+imtiX+KQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709809853; c=relaxed/simple; bh=hJdvsIf49qX5qYBe3jlnJZHHA33f29octtPbTBvXNM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qasgzkDNkHxPHdstCW0WLMOy2sHdPTpwhLRQYRuWVFRyZTFA2pn4Orn8BhzGM/foOS5SfYMJIRBJdq1dN/KAGWYhipT5yl5v5kDTdtsNfzqvFvmP/3HNDZyBLO0BQq8NK6eRrsSAtk7D0+A23iq0bAcQ/XdoKwv5qBDzN+8pNcI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Vpra+LW8; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 508D460004; Thu, 7 Mar 2024 11:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709809849; 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=OnOBH7X5Za0alGDnm8qdXNdP8bUSPL0B1vzgu9qjY6M=; b=Vpra+LW8UMKnWODdqEuBvDPXNDNUyvxrf5N2iTXeJ8IN4vJT+iOtUJwcRzodM1ri8oWq1G uQ/nI/+3VVORERnZwRtlq93LJDodjZF0MvqbHg6ODQRp2TKsQ1I+0AfRTHfNkcthzpIIC4 DYWZmPk24KCk3Ye1PNOlh7UBUSUHnRGaeiULqbNPegVjFUkWuBbH4Q3R3ezuXRSVwT0n05 Zq0U9LxFRchRGFRCqq6a3Yvb9TTthYzfrQJtJdPElklKvNLvfxDQuhc/8oxIyYBFg9Txsq S1TPJ8v/AGGpAK/ens5ycmqUX+5Q/UIZ+IYMbEduXSwWYnqbyM76c2LhR3Bu2g== From: Herve Codina To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Saravana Kannan Cc: Lizhi Hou , Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Luca Ceresoli , Nuno Sa , Thomas Petazzoni , Herve Codina , stable@vger.kernel.org Subject: [PATCH v5 2/2] of: dynamic: Synchronize of_changeset_destroy() with the devlink removals Date: Thu, 7 Mar 2024 12:10:01 +0100 Message-ID: <20240307111036.225007-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240307111036.225007-1-herve.codina@bootlin.com> References: <20240307111036.225007-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com In the following sequence: 1) of_platform_depopulate() 2) of_overlay_remove() During the step 1, devices are destroyed and devlinks are removed. During the step 2, OF nodes are destroyed but __of_changeset_entry_destroy() can raise warnings related to missing of_node_put(): ERROR: memory leak, expected refcount 1 instead of 2 ... Indeed, during the devlink removals performed at step 1, the removal itself releasing the device (and the attached of_node) is done by a job queued in a workqueue and so, it is done asynchronously with respect to function calls. When the warning is present, of_node_put() will be called but wrongly too late from the workqueue job. In order to be sure that any ongoing devlink removals are done before the of_node destruction, synchronize the of_changeset_destroy() with the devlink removals. Fixes: 80dd33cf72d1 ("drivers: base: Fix device link removal") Cc: stable@vger.kernel.org Signed-off-by: Herve Codina Reviewed-by: Saravana Kannan Tested-by: Luca Ceresoli Reviewed-by: Nuno Sa --- drivers/of/dynamic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 3bf27052832f..4d57a4e34105 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -9,6 +9,7 @@ #define pr_fmt(fmt) "OF: " fmt +#include #include #include #include @@ -667,6 +668,17 @@ void of_changeset_destroy(struct of_changeset *ocs) { struct of_changeset_entry *ce, *cen; + /* + * When a device is deleted, the device links to/from it are also queued + * for deletion. Until these device links are freed, the devices + * themselves aren't freed. If the device being deleted is due to an + * overlay change, this device might be holding a reference to a device + * node that will be freed. So, wait until all already pending device + * links are deleted before freeing a device node. This ensures we don't + * free any device node that has a non-zero reference count. + */ + device_link_wait_removal(); + list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) __of_changeset_entry_destroy(ce); } -- 2.43.0