Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp45004pxa; Mon, 10 Aug 2020 18:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/y50BErmYynAeRdIW9kai8eJTp/Fz7uNOxFy6FS47NPgITi1PcqwZUx1hFqdIpo+bJL9v X-Received: by 2002:a05:6402:1443:: with SMTP id d3mr24544465edx.40.1597108127420; Mon, 10 Aug 2020 18:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597108127; cv=none; d=google.com; s=arc-20160816; b=Uf1L4Xu3nmQ9JM3137KeIZ7R8CTBVDJ+U+70hegI8wZteTT3nSPSncSdIaSWBT9Gey txsGAfrN8DXBFx6zBbvpKmyTgH6UU/0TPvuVOpmxKCwVlwtGYlhiFEsfyjylfuWKgZHj ZlT90gcOX16+1HYHPfVDveqpnTtoMn8U6A1Y66ywEQmM7AuQv+CqhpN9kH40jU+FnnPY rDIXKhaesOjwZlNZX/Y9khErTWGmQmUaOXFf3QqDarjTEX6ve1QFu4QiIdWDp4Lr+HJe Bbb09XXBRBOqSBzJWWz7C3Y4zvkC7jBfZrWThPA6nHtjy+etr5U0FMQEO9IgqPqQayFx FIqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:content-transfer-encoding :mime-version:subject:from:references:in-reply-to:message-id:date :dkim-signature; bh=EDQFCHOwxK5MJ6Gt0jZIdDf+nRTfD04a23SbkIr5+qQ=; b=uWNRnBn3jwxaa9Wrt4xkxEHJg5cGLrLIEPL6i4z3m/7uOVOuiUEonMggseLoex3epT 8dgx2gBNCCg9G8gHmQrEohJjwYKmL+fZfnv7kUOqv9C48UnF//nFQc+sQfDgKH3mf6Aj uRb0QLrPWGzgYp6zqqYCD3hrqCn/wFWdQ/TWA9IAwMd+Q4gmL11ehY8dfggNR1zOhif5 l3r4rTTCmP+fpTpD73wBO2b+ntO7+WeAF9EBph5+O5Przgi0BMra9+iGE0jDJCFrxPww IXESteP6jgHibcHi/OQBrCht9in+0e1TExENMpxfOtg0+7K2JwuyBAp0uWU4Q5/TD/ks Cw6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=qhrHgMxz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si12042212ejm.274.2020.08.10.18.08.22; Mon, 10 Aug 2020 18:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=qhrHgMxz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbgHKBHt (ORCPT + 99 others); Mon, 10 Aug 2020 21:07:49 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:23898 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbgHKBHl (ORCPT ); Mon, 10 Aug 2020 21:07:41 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4BQZSW07gnzNH; Tue, 11 Aug 2020 03:07:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1597108059; bh=I1YYHRYByEQpnexzWJYpaabhHYOB7QOBwttBNq6vd6s=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=qhrHgMxz4Gd4zo3MkDQbWk9eWkD7Tc1gqPwLmq/JTXpD9KzUBxmmB4Zv4LULBrqGv L6XLMqQmtS+Tw9ZKMejhyqeYzcnfdlp+hKDv3c0MyUdGoyhdmwtvqtETpda+djRYhT InqwQLXHq+cC+2e+Rg4Cb/xo9sOylDNDXpxdBdBHcjQUOlwqJOoMFm8ORDdZI9AhGn RpVrrTLr5yMZKmnjQBNxrmnkUw0AB7E1ynoVqyxuw8dWRuTkst2sI1QYadGkmdFQ3N 1slcCsbSk74W0VyV7fXIwixZD95qPFgrbRKRqDiOGkfHg8yvyizVI1jl95Z0w3PjFj 4to8VZKNPuE4Q== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at mail Date: Tue, 11 Aug 2020 03:07:38 +0200 Message-Id: In-Reply-To: References: From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH 3/7] regulator: push allocations in create_regulator() outside of lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: Dmitry Osipenko , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Vladimir Zapolskiy Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move all allocations outside of the regulator_lock()ed section. ====================================================== WARNING: possible circular locking dependency detected 5.7.13+ #535 Not tainted ------------------------------------------------------ f2fs_discard-179:7/702 is trying to acquire lock: c0e5d920 (regulator_list_mutex){+.+.}-{3:3}, at: regulator_lock_dependent+0x54/0x2c0 but task is already holding lock: cb95b080 (&dcc->cmd_lock){+.+.}-{3:3}, at: __issue_discard_cmd+0xec/0x5f8 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: [...] -> #3 (fs_reclaim){+.+.}-{0:0}: fs_reclaim_acquire.part.11+0x40/0x50 fs_reclaim_acquire+0x24/0x28 __kmalloc_track_caller+0x54/0x218 kstrdup+0x40/0x5c create_regulator+0xf4/0x368 regulator_resolve_supply+0x1a0/0x200 regulator_register+0x9c8/0x163c [...] other info that might help us debug this: Chain exists of: regulator_list_mutex --> &sit_i->sentry_lock --> &dcc->cmd_lock [...] Cc: stable@vger.kernel.org Fixes: f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking") Signed-off-by: Michał Mirosław --- drivers/regulator/core.c | 53 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3dd4d4914075..c95397798275 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1553,44 +1553,53 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, const char *supply_name) { struct regulator *regulator; - char buf[REG_STR_SIZE]; - int err, size; + int err; + + if (dev) { + char buf[REG_STR_SIZE]; + int size; + + size = snprintf(buf, REG_STR_SIZE, "%s-%s", + dev->kobj.name, supply_name); + if (size >= REG_STR_SIZE) + return NULL; + + supply_name = kstrdup(buf, GFP_KERNEL); + if (supply_name == NULL) + return NULL; + } else { + supply_name = kstrdup_const(supply_name, GFP_KERNEL); + if (supply_name == NULL) + return NULL; + } regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); - if (regulator == NULL) + if (regulator == NULL) { + kfree(supply_name); return NULL; + } - regulator_lock(rdev); regulator->rdev = rdev; + regulator->supply_name = supply_name; + + regulator_lock(rdev); list_add(®ulator->list, &rdev->consumer_list); + regulator_unlock(rdev); if (dev) { regulator->dev = dev; /* Add a link to the device sysfs entry */ - size = snprintf(buf, REG_STR_SIZE, "%s-%s", - dev->kobj.name, supply_name); - if (size >= REG_STR_SIZE) - goto overflow_err; - - regulator->supply_name = kstrdup(buf, GFP_KERNEL); - if (regulator->supply_name == NULL) - goto overflow_err; - err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, - buf); + supply_name); if (err) { rdev_dbg(rdev, "could not add device link %s err %d\n", dev->kobj.name, err); /* non-fatal */ } - } else { - regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL); - if (regulator->supply_name == NULL) - goto overflow_err; } - regulator->debugfs = debugfs_create_dir(regulator->supply_name, + regulator->debugfs = debugfs_create_dir(supply_name, rdev->debugfs); if (!regulator->debugfs) { rdev_dbg(rdev, "Failed to create debugfs directory\n"); @@ -1615,13 +1624,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, _regulator_is_enabled(rdev)) regulator->always_on = true; - regulator_unlock(rdev); return regulator; -overflow_err: - list_del(®ulator->list); - kfree(regulator); - regulator_unlock(rdev); - return NULL; } static int _regulator_get_enable_time(struct regulator_dev *rdev) -- 2.20.1