Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp685913yba; Fri, 12 Apr 2019 11:34:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzneZ1QljsopnQljS5IZtQiI1fp+ywqiXfTAXsj6b57I0d+rVeweBGejlGm2O8JUSV/NhL8 X-Received: by 2002:a63:6a43:: with SMTP id f64mr22485659pgc.366.1555094053542; Fri, 12 Apr 2019 11:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555094053; cv=none; d=google.com; s=arc-20160816; b=Ho74PnAfWdlP4x5xTfHuumsDwcm990DmLJlwIF38EKsZD8nW0hCWnFT7bwnjmTFZzZ vDbV/zmMwiRt0xtXmb5YWtGVyQ1Sqn571vZZzbaAJ4RdUthSGW0q7A1VL69YWB0RBx7Z CE268jGzWl7zGcYNJRZugVFLypWYmWXrhG1jWa/6mj7wT4yqga/rUhjo4D5i+ECdGGHI quRg8L+6o47kn/bLuGdNRx0720IbrNq/LE7mM6Idgin5iWKh8cPMbqTTJOOiFGSXh/BV b7Zjis+HDW/7xlsee4Hf9AGyD20d6CiORagf6I2uTueuPO1OWXML+DAkKGJAWIwukm85 zapQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BVJn7EMSVcJ1jn+dFeRvno3fUruxxkGj0fYb7YIIqgk=; b=pl6sZY0S4mphusTjQLwDHogWlpenUCwSvyuJ6bZhiWYH39pElyVmQ9KTykKR3ZiLV+ wpbVF+7Utz3GeivLdrRr8DgHzO31YCvht0pP8oUIWLdGedjqJ96Ym+5q7TxhgFLLccay 8/zCE6XiNrBM3rQh1LSJZauTpofBlM5sng0IStmf3SWivmssT3H1G51t53/qgeGhPN2R 2Q29R/Tarp1EQz/oMYSs49t5U2uCXBSq6ffhW9DS/Giq7c4KdnGML0LosEs/72LaUrKH On11Z2oHUKGXrLQ6rDsTdtuuTi0Ku1Gz3dcvsvK1pwKy56QWafiYd1BRzq5Szn2MNH/u cuNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QMXmOtwP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si30359502plr.110.2019.04.12.11.33.57; Fri, 12 Apr 2019 11:34:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QMXmOtwP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726958AbfDLSbw (ORCPT + 99 others); Fri, 12 Apr 2019 14:31:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:50318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbfDLSbw (ORCPT ); Fri, 12 Apr 2019 14:31:52 -0400 Received: from mail.kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F938218CD; Fri, 12 Apr 2019 18:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555093912; bh=HyBqBJLbHWUeQWX+cb/C4Wl/25IHsJuOK2Xzn81HSvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QMXmOtwPTjD3kYgTbLxwvmjtmR2Oh8CWSUl52Dngr7bq+iyhKqnvaIxOIzVXhv7gL ms0+qyKR37MOnzXVeYeWvB+fShmPKMgL01WWk+/PJhMRyKyUMhzNA1v/bOjJ7YB9/h GAeJxlt3FdmcRWL0LXoXEFIfJa4Zqdnsm9Rc1zac= From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Miquel Raynal , Jerome Brunet , Russell King , Jeffrey Hugo , Chen-Yu Tsai , Matti Vaittinen Subject: [PATCH v4 1/9] clkdev: Hold clocks_mutex while iterating clocks list Date: Fri, 12 Apr 2019 11:31:42 -0700 Message-Id: <20190412183150.102131-2-sboyd@kernel.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog In-Reply-To: <20190412183150.102131-1-sboyd@kernel.org> References: <20190412183150.102131-1-sboyd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We recently introduced a change to support devm clk lookups. That change introduced a code-path that used clk_find() without holding the 'clocks_mutex'. Unfortunately, clk_find() iterates over the 'clocks' list and so we need to prevent the list from being modified at the same time. Do this by holding the mutex and checking to make sure it's held while iterating the list. Note, we don't really care if the lookup is freed after we find it with clk_find() because we're just doing a pointer comparison, but if we did care we would need to keep holding the mutex while we dereference the clk_lookup pointer. Fixes: 3eee6c7d119c ("clkdev: add managed clkdev lookup registration") Cc: Miquel Raynal Cc: Jerome Brunet Cc: Russell King Cc: Michael Turquette Cc: Jeffrey Hugo Cc: Chen-Yu Tsai Cc: Matti Vaittinen Signed-off-by: Stephen Boyd --- I plan to take this through clk-fixes for v5.1-rc series. drivers/clk/clkdev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 8c4435c53f09..6e787cc9e5b9 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -46,6 +46,8 @@ static struct clk_lookup *clk_find(const char *dev_id, const char *con_id) if (con_id) best_possible += 1; + lockdep_assert_held(&clocks_mutex); + list_for_each_entry(p, &clocks, node) { match = 0; if (p->dev_id) { @@ -402,7 +404,10 @@ void devm_clk_release_clkdev(struct device *dev, const char *con_id, struct clk_lookup *cl; int rval; + mutex_lock(&clocks_mutex); cl = clk_find(dev_id, con_id); + mutex_unlock(&clocks_mutex); + WARN_ON(!cl); rval = devres_release(dev, devm_clkdev_release, devm_clk_match_clkdev, cl); -- Sent by a computer through tubes