Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3845482ybl; Mon, 12 Aug 2019 07:20:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVD5rTqLfdjRqY6MEzmAkdpg58+/iiBC4TXhTKlKmd+CswRgTenClE5rBBggXZQd3KwWr1 X-Received: by 2002:a17:902:8649:: with SMTP id y9mr5852803plt.252.1565619653372; Mon, 12 Aug 2019 07:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565619653; cv=none; d=google.com; s=arc-20160816; b=bVDZ2IREVaLCoNRe/uCJZDhQkSefiH10dANNmb2chcRz9ALxYL1mbCL2kR/U4Y1PDu 2SA/7GfUFkI+KbB3A0G9eVg2+Dvn0qYLb3QIuN+a1DG5lFGPnolNN6poTAmUYEAt31su qnceua5b5H0b2L1vQy+oApGW7RWodmqy3aIB9tLGukXdD+xr8oJgvqQB3rfI6eX+8d1j B5akWKSZrcjT9+1x7XTJIRHr1iWos8Z7Z6ilA87zLV5mn6gBYMuEJG4J9PsgeKxx8WMY qCs5ET9HG26nBUwoYM+1NQ9G0ehwvi20Mv/2Mm/DH+sKU8kn0SyY0edWRqNJlapjeG0f svoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=iivSnktAPjnlSD94HraPJYOzwcYbsXnIpC6UfUdyt1w=; b=HkoGrZT536qb6lG12FS1JYGMmrRT3OaADrTfc2yPBnM5T9KvL2NL/sy6pwS3LI0BXZ Nas8D8wbDFjs7bH0WJsJ8O7awrUz1p3hP6wZQVXRlrLzDyGoxtZ9b+czk97xcSkpLtiy BdNDe9jqWcSHpyM3TsPHLT8qwC5fTTLxqC/oOj9GGa0hMAj4bjJ/HV0zACFjZlduG8Zw Q7kA+uwRR214MLysi9Kk+TnphV8Cl6Lb7ClsjqCnh/8UJOT0EtyBFOjfKIYmLUQO+xxW 0DW7CmFYO7K/sy3fvPKL8br0SPIx0ztqkGZGNG5myqjTdjMS4tAt6WXRgAHYnvPRNZ1K gy7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fMOs+pdP; 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=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 94si12908000plf.221.2019.08.12.07.20.38; Mon, 12 Aug 2019 07:20:53 -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=@gmail.com header.s=20161025 header.b=fMOs+pdP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727444AbfHLOTq (ORCPT + 99 others); Mon, 12 Aug 2019 10:19:46 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:45327 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727206AbfHLOTq (ORCPT ); Mon, 12 Aug 2019 10:19:46 -0400 Received: by mail-ed1-f66.google.com with SMTP id x19so97907678eda.12 for ; Mon, 12 Aug 2019 07:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iivSnktAPjnlSD94HraPJYOzwcYbsXnIpC6UfUdyt1w=; b=fMOs+pdPUCunxL+VlNcjw0inCDUYczP4DNptKnjmA+iIs5iSqH+wFAb8OrnnzW+/WA dKDu7dbSukUIPfTFBWJhE/zpPpNi4d/npgGREOyPQobiFFC3IkgFfnIRh5pau+IDtYkB zIo9yf9VPrennmv7Um0d2pvSe/Fi9IFiNOn55hi69JQbNsX/Ye5yN7O5CHomfR/atg0U jRyjuKUVRfUTjYa79LmeQYD6FjnhXfPmX2Xcpxlgw3b0e21TR6gNCSzw/QzpZLPqoOwE b5LuCj6lzisfF7UXyeh8hseX96dcFgAWM/BpeA6nnDEk63beE/fsFT0cKPfX2iq/FsyX CGUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iivSnktAPjnlSD94HraPJYOzwcYbsXnIpC6UfUdyt1w=; b=WOmKFHVxhPWIWDL0ZjGRGW1ct/TpAsYJYbwrhGLanrtloKGF1w0AHcrWr/61apbk3x rLs2V0bClhaElsKWIrSrCiua3Ppbt8WXvyLBc/iNTaYR1TczaxKJgYAO8s755QJc87V1 mLl32Jpyr330z+bb1kk1vAVA7oZKWsNpZUXhSLZDqah2g1RV8lYgVpt8gk3mYpPkzFuG pCHbVFpPjQswxM6/PsDw9g+cZyGFU6SBF2dcT2lNmvenDP2bX4r4tEAxYDW2h72nOCKf l1oWSWA2lcGd0xN/2b0nljVTDMXamuIrSxU2916h0FlX3tidfTx9fEtpQVid99kx32hr RDtg== X-Gm-Message-State: APjAAAXk/iiPzlGwwhXVYkAVtaUHfz7hYcQOe6l5rNNuXmF0HCvZYmad bBVzbITRU4YIirvKYu9fDBk13n+yCLusmZo1V4otlQ== X-Received: by 2002:a50:b66f:: with SMTP id c44mr36867903ede.171.1565619584492; Mon, 12 Aug 2019 07:19:44 -0700 (PDT) MIME-Version: 1.0 References: <20190809030352.8387-1-hslester96@gmail.com> <20190809151114.GD3963@sirena.co.uk> <20190812110719.GE4592@sirena.co.uk> In-Reply-To: From: Chuhong Yuan Date: Mon, 12 Aug 2019 22:19:33 +0800 Message-ID: Subject: Re: [PATCH] regulator: core: Add devres versions of regulator_enable/disable To: Mark Brown Cc: Liam Girdwood , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 12, 2019 at 8:51 PM Chuhong Yuan wrote: > > On Mon, Aug 12, 2019 at 7:07 PM Mark Brown wrote: > > > > On Sat, Aug 10, 2019 at 09:44:45AM +0800, Chuhong Yuan wrote: > > > On Fri, Aug 9, 2019 at 11:11 PM Mark Brown wrote: > > > > > > I'm not super keen on managed versions of these functions since they're > > > > very likely to cause reference counting issues between the probe/remove > > > > path and the suspend/resume path which aren't obvious from the code, I'm > > > > especially worried about double frees on release. > > > > > I find that 29 of 31 cases I found call regulator_disable() only when encounter > > > probe failure or in .remove. > > > So I think the devm versions of regulator_enable/disable() will not cause big > > > problems. > > > > There's way more drivers using regulators than that... > > > > I wrote a new coccinelle script to detect all regulator_disable() in .remove, > 101 drivers are found in total. > Within them, 25 drivers cannot benefit from devres version of regulator_enable() > since they have additional non-devm operations after > regulator_disable() in .remove. I find 6 of 25 can benefit from devm_regulator_enable(). They are included in my previously found 147 cases so I incorrectly skipped them while checking. Therefore, there are 82 cases that can benefit from devm_regulator_enable() and 66 of them(80.5%) only call regulator_disable() when fail in probe or in .remove. > Within the left 76 cases, 60 drivers (79%) only use > regulator_disable() when encounter > probe failure or in .remove. > The left 16 cases mostly use regulator_disable() in _suspend(). > Furthermore, 3 cases of 76 are found to forget to disable regulator > when fail in probe. > So I think a devres version of regulator_enable/disable() has more > benefits than potential > risk. > > > > I even found a driver to forget to disable regulator when encounter > > > probe failure, > > > which is drivers/iio/adc/ti-adc128s052.c. > > > And a devm version of regulator_enable() can prevent such mistakes. > > > > Yes, it's useful for that.