Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2821838lqp; Mon, 25 Mar 2024 10:07:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5KGe7gBWKIwjcQIY8wam2mhX96K243tQHfa+DzRt9adbItmSo7zWOgsVKBeAOZpmmXtx9NlmfOZG65Fk5znOGf3cIjeb9eiTPkM+6Rw== X-Google-Smtp-Source: AGHT+IEShqrH+axBDGOl8GTJVeDuEjwM5MPt1ssKMs5/axtKiFbWqFYyFz7yG9lQCLw5coIS85Ub X-Received: by 2002:a17:902:b108:b0:1e0:6a:1c01 with SMTP id q8-20020a170902b10800b001e0006a1c01mr7680933plr.52.1711386434293; Mon, 25 Mar 2024 10:07:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711386434; cv=pass; d=google.com; s=arc-20160816; b=OCL/eClfna46oCywrlWgkkPll6uXbHECZ3I6Vum+QK7lGeg+elxw4m6kyLlq1WZwFR fdzy5jwlfT6pUifGfDeyuKbz92GTdYCWRkWpVsrQOXQLfbrevvsNAjbLP1POb19GFB0Q 6E6u7mI2vXxN/GQkN6foO3bRCLtnpoQ0jpstDXQlwQ4PQBTg60Tn9Z/D7NCnWAn1Is70 KUujuLNh8AvWdLoGeDALYf1G7wIvcjCNlmRu9F5papQISs/yP0iV/mDy5Bq0tFwILaWK pS9YBg37oGnIck4MSChSuyvgL9rHCInaEKO8lx3wTuHQ1dBJlvcL6iQGnc1wlyZF9PiD QCXA== 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=FQr/k0s/kJSMD8sx4HhB7DuZAab9W+v4kyea1IFYzds=; fh=JfsClYTjt8qDhUqyVlL6sma6bIUBcmxkDWND1AnjMEI=; b=jQj/sAcRoi7B46PfXWakTWiG5z0FmKTNNwOUT9vIdOBCKTk9G220CXCvrashCghROS MdPztWOCFA42Xm36lAIS4WbOYtTnS/NcpaOKpcZBb7JRAXDfXimSgEBcBIaXpxwAvh4e FwouR3DuLuy5uhNj9klHqiDJrtZ+CuREAquru5wDD/i87bHci6B95Q00Hrk/PsJ7ymjR evCrOHZnDUe6lRmVbywTsiNYRQ2xw9p+mRQLYioHp5CX5Bkf7VMSJG/pIwc+9aiGcfXM UizNJDKsrJvoW5CDDLwMVXT6uT35vsYy67Nz9UCqa0EstKtoeV/ktudwmVxINJoiti6m bssg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=pXf3FPYp; 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-117356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lq14-20020a170903144e00b001deec70b148si5330347plb.17.2024.03.25.10.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:07:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=pXf3FPYp; 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-117356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117356-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A1BE3029CF for ; Mon, 25 Mar 2024 16:57:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75EE8140362; Mon, 25 Mar 2024 15:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="pXf3FPYp" Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 4952C13CA97; Mon, 25 Mar 2024 15:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711380122; cv=none; b=lGTjzmQQ76d94PVUoT5+5hRfxJhjLGOeAyC6Dq0Lfilmautq88YEzKFoI3v381rM6D/KEUMBFvDo0reAs9BazweZ5lk6IrkkBXoP2yi05s+E7zJuYJ63RwDYgeh/26Kp/rjtFT3z4W73+mU2RzTVN0SU+OaaRRwqESlZzdQ9OCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711380122; c=relaxed/simple; bh=irAAEUcrV7xB4jx4nOrL/PVBhqWchwYDIeJsAg7Sbj0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yrw9RuFBaZTvLYW4MS37YCN8PTtFvFpa7vKb8AcqoKsKlqgvWYDuvgfwvGNRBTox4dHmKDDay3VPzc9U/BsdRGIntoxwKI3BoGrvmA/gmE+0T9fTuuEFiKq28MYFO0OXKvV3yDywpl2wSg6Vq/VHzVQR0XAidlSldf9iPTEYSzU= 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=pXf3FPYp; arc=none smtp.client-ip=217.70.183.199 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 BA4F2FF80C; Mon, 25 Mar 2024 15:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711380118; 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=FQr/k0s/kJSMD8sx4HhB7DuZAab9W+v4kyea1IFYzds=; b=pXf3FPYpsieWAC0uHiLlYblaEjvpxd0eCYtiKvgub243wBLecvqcb3NLlGPKHG3oW2kRYl W8Vat7B94mhIYuEjvjrFI3slIFbUSWN2q7msRTsyRP/whf3Nqc3dlLx9/ghJP/usPBKi5n MyBWc03pJkDKzh1ocH37lFDAa1E93RpTFVM+SZN7CPiz8FKi0KDrSXVdwVoONJzHUBjsph 9gv1Ev6C/tGOyTbVhkiE1zAxotBQonTXin0kXmURg/jG65FoSNtXLIXapElOEGuIP6Knuv pz5q33xYLlybq1+61DAZAvijHap9fgYKw5nYzo99gf2NfqcLgq3MGbhOWwVI3w== 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 v6 2/2] of: dynamic: Synchronize of_changeset_destroy() with the devlink removals Date: Mon, 25 Mar 2024 16:21:26 +0100 Message-ID: <20240325152140.198219-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240325152140.198219-1-herve.codina@bootlin.com> References: <20240325152140.198219-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.44.0