Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7625121ybh; Thu, 8 Aug 2019 20:05:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSCHV2YTuKryJysMIXAQd+8g++5hj4iGtsEf3sGiMIQ+9F31tgsRN6vu+ynHXiQTX6Tsqu X-Received: by 2002:aa7:8641:: with SMTP id a1mr19063563pfo.177.1565319931810; Thu, 08 Aug 2019 20:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565319931; cv=none; d=google.com; s=arc-20160816; b=elLFiaGkpLwBZ3+EDJPHR5uEMQlIes2PyzZVv/Mz1/GzJBEiV7B4y981xTJoPr69XQ mawF4AlwQ1eBkHaa59Y6k4j4nOPdIY4D9iXAVo5AVOGf1MQg39CUWWosNJGE6IVtHyvC S5IwGJVOSHdtME+HeMcsqSpOIqMJGd5x88MimvfFunZYTAZj6uqgC3yOZpXPJWA0WqTm Ai7bPNLEsxEtBLEbDf0Aum/CYbJi8RQ0DuTjFKJWOafUv/63JWOtypmB+cfKfXSi/C/v mOFVfFB98CIKOjF7u00lABg//P38EvThhuknpY9loACtDqT7dhi2ca029eBM3Nj/tgl+ YoWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=tkv9lR0hAtLKOW5gkirlFYTKguflMZvyPqUX9XJEFP8=; b=hiTBsO/f1HOmyKvzcYFzXOt8WfO7HGdudjRAqYhsrvn3qXUwUK0TbRwPgS9uynBkwd upRSgsE6wLGM4FINcNOYDG3s6HHNzeBRGutgirT80PW2ZiQu5BCDWmQXkhNcAIBC8VUe IUlJ9m3CJgFFBvUIK+k+XdKh/mcmO/0h+x1MNg3OfrTRJ8VxXH8Z04o3RdJpMiby1uQL EefVVLuBUa+TvINW27TBVrqGYdN8Mbp4ohu+JjHZ/yvssYopW6LmBuBVUv5l5RO/Z2pi 6CICzVhq80C1wWvEv1dQyi7mRL5YVVu3TgFBfP3PnC8ilDQGosuFXWTqcpJ486N/uHQR s/+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ig+OAtP2; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m17si23176241pgc.461.2019.08.08.20.05.14; Thu, 08 Aug 2019 20:05:31 -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=fail header.i=@gmail.com header.s=20161025 header.b=ig+OAtP2; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405390AbfHIDEB (ORCPT + 99 others); Thu, 8 Aug 2019 23:04:01 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42624 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404533AbfHIDEA (ORCPT ); Thu, 8 Aug 2019 23:04:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id t132so45094947pgb.9 for ; Thu, 08 Aug 2019 20:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tkv9lR0hAtLKOW5gkirlFYTKguflMZvyPqUX9XJEFP8=; b=ig+OAtP2gw5ZGHC7kb/G98hh1FK4Wc2v1ulYMIqyuuB6U+aEQ7jDqrZ8+nunqgl9qt /gqgfZC0z3eeznbxr4Hsmatv8pY/Z8Y1IY/kKL85tzlhKcx24pVXNM9df3jmdz9+/ngu lUDBmY65fid2RtFO3K7RM4pFiDfPNf7B3PEdd/IfblT1GhnK8cMSa6TkqALPRM8A1N3n nQPaXYSBA7yKqsy7yEI2T2iYNjK6WJ3z9JVa8OCLatuyyleapeWvVYHKKXwSx7ke0Cgi R4g8yd/9XhVruVrmgHEr6l9FSgmRHILnwq/BfoCp2CrrbEfxxnoBQUPaJsVfMshYVqfY 1SKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tkv9lR0hAtLKOW5gkirlFYTKguflMZvyPqUX9XJEFP8=; b=tA+vRuOeQmzrxc9S9qzR2eRLZZDTbetCmzXN5lbRwV9ZdFeKjP7Rd++bd/+RuPbdHu B48LDKitWs928/Ks4DKoHXzxDTQc0kHAL0yKR/uYPy9Atibwl8HQwTsN7hT2SED9kf7T dHXoHPYifwTz4ZDEgwcn+i1uZiKFL6iddR6l1khV4QSImeLmFOfl+F3MCYCVrGjWqM8q H+GnDMAVAxg7M//SYJzpSlDXFP/T8RafZqVavtad06OjffXlqZz05LfEYmerueKBcMRS pEKAgzO0dSJa7KpjCJkn9bxsSndOmU8SWKWoYPEwzwDgNXZyRmNCdt5c7BI7/gveqFgv uG4Q== X-Gm-Message-State: APjAAAUNVLsKdvrO/DUWzUhrUf9I/esl68NkOc+j/PdOeXSMqo5vBP9u 3tCO7rGRSet2hCDe4GFpS8s= X-Received: by 2002:a63:f357:: with SMTP id t23mr15859793pgj.421.1565319839914; Thu, 08 Aug 2019 20:03:59 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id o14sm3556284pjp.19.2019.08.08.20.03.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 20:03:59 -0700 (PDT) From: Chuhong Yuan Cc: Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH] regulator: core: Add devres versions of regulator_enable/disable Date: Fri, 9 Aug 2019 11:03:52 +0800 Message-Id: <20190809030352.8387-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I wrote a coccinelle script to detect possible chances of utilizing devm_() APIs to simplify the driver. The script found 147 drivers in total and 22 of them have be patched. Within the 125 left ones, at least 31 of them (24.8%) are hindered from benefiting from devm_() APIs because of lack of a devres version of regulator_enable(). Therefore I implemented devm_regulator_enable/disable() to make more drivers possible to use devm_() APIs. Signed-off-by: Chuhong Yuan --- drivers/regulator/devres.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 3ea1c170f840..507151a71fd3 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -115,6 +115,61 @@ void devm_regulator_put(struct regulator *regulator) } EXPORT_SYMBOL_GPL(devm_regulator_put); +static void devm_regulator_off(struct device *dev, void *res) +{ + regulator_disable(*(struct regulator **)res); +} + +/** + * devm_regulator_enable - Resource managed regulator_enable() + * @regulator: regulator to enable + * + * Managed regulator_enable(). Regulator enabled is automatically + * disabled on driver detach. See regulator_enable() for more + * information. + */ +int devm_regulator_enable(struct device *dev, struct regulator *regulator) +{ + struct regulator **ptr; + int ret; + + ptr = devres_alloc(devm_regulator_off, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = regulator_enable(regulator); + if (!ret) { + *ptr = regulator; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_regulator_enable); + +/** + * devm_regulator_disable - Resource managed regulator_disable() + * @regulator: regulator to disable + * + * Disable a regulator enabled by devm_regulator_enable(). + * Normally this function will not need to be called and the + * resource management code will ensure that the regulator is + * disabled. + */ +void devm_regulator_disable(struct regulator *regulator) +{ + int rc; + + rc = devres_release(regulator->dev, devm_regulator_off, + devm_regulator_match, regulator); + + if (rc != 0) + WARN_ON(rc); +} +EXPORT_SYMBOL_GPL(devm_regulator_disable); + struct regulator_bulk_devres { struct regulator_bulk_data *consumers; int num_consumers; -- 2.20.1