Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp47227pxk; Tue, 15 Sep 2020 17:22:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnbE3xigMO2gv4pJ0GNIjEyp4TQa88aHj+kdDy3iXjdBbKFk0Dn6JOMiYevSOuwVvkozYq X-Received: by 2002:aa7:df14:: with SMTP id c20mr25292462edy.334.1600215765872; Tue, 15 Sep 2020 17:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600215765; cv=none; d=google.com; s=arc-20160816; b=oHAq17ebVjvWx0Fvu1iUKzFeZc39BXIVXazfqbVTRFe2Xp1OjmU9ndDmNCUbEzKa4+ JsJIR3rTfRqneANmNj5fRKa+punzlxTgDXsqFst+GOGcyD+Epf2CQeebU3rzmIdkOMxy 254d5WfTDCwfZILLTkVe670vUPt1yJg/fBQ/8JKyEIjfEKQGtEfG5afrlpzn7ZzijtBL gUNgfApE4mbnpVCbOfIYgLdYtyieytQErIoTaBviRQRxhzHWhqUUZBLnUJj+FXu1Ckhv mxk68OtrJ876e0iNCiLGsRhNgDhn46x6mPDpH6GmECtYEb03wVNz3z0WY93Z3NZ9R8yG /zlg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e74xkXszXlxx+M0elanNDND4+D7Qm3gkpeShRDiL6VI=; b=g1ArQWoq8yhjPvwPSozCTc37cn0H3OMRorDe2xYPDNX367oKHX4pb1tACosVb9Yj/z RwccSkrSEX/8CWuvuC//7NooeqsVjQ0o+8wfwDBeB9WlvIsRH+eGIlt7yhZJaE8J5W33 dOiVqBqmHr24MUBSTdGaFjLYYNSwkwccQMJdh2YGDstI6nd0Jp2aHEEi0O8viZe0I17n A394k6AK2F236qU2DZZev/woFkIAheGQ4QrjlVybEVX1z69uvlPX6OnJM5Sd1qqc+kbI U2xozRz4YW/yIT8gvdbSCRdinJ+MAWkzBzmvxwuRXIQ0Y27GSAVy2yFNKcmB4djdc7K+ tCcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bZPTTSNy; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n26si10263733eji.66.2020.09.15.17.22.23; Tue, 15 Sep 2020 17:22:45 -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=@kernel.org header.s=default header.b=bZPTTSNy; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbgIPAVo (ORCPT + 99 others); Tue, 15 Sep 2020 20:21:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:37098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgIOOVg (ORCPT ); Tue, 15 Sep 2020 10:21:36 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C258622264; Tue, 15 Sep 2020 14:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179436; bh=JCN+z4P1uefTgGQWZHueo4+UFFSOUFLmxaYwH9BMxcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZPTTSNy3pMN3xXEzNEdW9LMB5xfz7wQB84DDs1OwtAuHwycu1YZmDJS/3eh4BOCM ndk8p0NgC0oRlck6G2hkDrXi984QX1cEOZTWUYI/qGue2Q2tsfW+rz79MsHRClbmiR zK0wJb36jblhWOPOcFnt3v2WqF0cYcerqFkPcWhM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Mark Brown Subject: [PATCH 4.19 58/78] regulator: push allocation in set_consumer_device_supply() out of lock Date: Tue, 15 Sep 2020 16:13:23 +0200 Message-Id: <20200915140636.480295884@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140633.552502750@linuxfoundation.org> References: <20200915140633.552502750@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michał Mirosław commit 5c06540165d443c6455123eb48e7f1a9b618ab34 upstream. Pull regulator_list_mutex into set_consumer_device_supply() and keep allocations outside of it. Fourth of the fs_reclaim deadlock case. Fixes: 45389c47526d ("regulator: core: Add early supply resolution for regulators") Signed-off-by: Michał Mirosław Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/f0380bdb3d60aeefa9693c4e234d2dcda7e56747.1597195321.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/regulator/core.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1257,7 +1257,7 @@ static int set_consumer_device_supply(st const char *consumer_dev_name, const char *supply) { - struct regulator_map *node; + struct regulator_map *node, *new_node; int has_dev; if (supply == NULL) @@ -1268,6 +1268,22 @@ static int set_consumer_device_supply(st else has_dev = 0; + new_node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); + if (new_node == NULL) + return -ENOMEM; + + new_node->regulator = rdev; + new_node->supply = supply; + + if (has_dev) { + new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); + if (new_node->dev_name == NULL) { + kfree(new_node); + return -ENOMEM; + } + } + + mutex_lock(®ulator_list_mutex); list_for_each_entry(node, ®ulator_map_list, list) { if (node->dev_name && consumer_dev_name) { if (strcmp(node->dev_name, consumer_dev_name) != 0) @@ -1285,26 +1301,19 @@ static int set_consumer_device_supply(st node->regulator->desc->name, supply, dev_name(&rdev->dev), rdev_get_name(rdev)); - return -EBUSY; + goto fail; } - node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); - if (node == NULL) - return -ENOMEM; - - node->regulator = rdev; - node->supply = supply; - - if (has_dev) { - node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); - if (node->dev_name == NULL) { - kfree(node); - return -ENOMEM; - } - } + list_add(&new_node->list, ®ulator_map_list); + mutex_unlock(®ulator_list_mutex); - list_add(&node->list, ®ulator_map_list); return 0; + +fail: + mutex_unlock(®ulator_list_mutex); + kfree(new_node->dev_name); + kfree(new_node); + return -EBUSY; } static void unset_regulator_supplies(struct regulator_dev *rdev) @@ -4375,19 +4384,16 @@ regulator_register(const struct regulato /* add consumers devices */ if (init_data) { - mutex_lock(®ulator_list_mutex); for (i = 0; i < init_data->num_consumer_supplies; i++) { ret = set_consumer_device_supply(rdev, init_data->consumer_supplies[i].dev_name, init_data->consumer_supplies[i].supply); if (ret < 0) { - mutex_unlock(®ulator_list_mutex); dev_err(dev, "Failed to set supply %s\n", init_data->consumer_supplies[i].supply); goto unset_supplies; } } - mutex_unlock(®ulator_list_mutex); } if (!rdev->desc->ops->get_voltage &&