From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BC63C3A5A6 for ; Thu, 19 Sep 2019 19:17:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D2152053B for ; Thu, 19 Sep 2019 19:17:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uoQrIbZG"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BEAvPSDM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D2152053B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7Qgqkv6nBFvOVi5u6noLq/TwMmVdobFXAKlOKvCIqWs=; b=uoQrIbZGoEfO8i uOnw+Z2LMKtCzvFX9GifNJ1ZDG9LGHI/Ll6UpLG9X0wGOFMj3F+y4UXWryqB42lEA1db2xjWWb4dw t+uspCzwcXvOvkxPm1jk3VEjniS5o7A/mvBEKIWLox4l4kMqpHCvA917VUtHctuoD57M0hNe4QE7B LLFQfzhi1aq0skfWEbgFANDprEsrX4dTRpKxxu1cHBZJzy6x4mI4wywzZdMTfiMvmqtje0WR4lC75 HSZAmXaOPFvwBuck6UpSshKVf5D61QMkcLjh7WBXhW/QAenDJIsRcabt5+6HsT8j7sBmZ5hcYXKG0 fmtjlBowPhtUW8+1sj9g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iB1vO-0005KU-AM; Thu, 19 Sep 2019 19:17:06 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iB1vK-0005K6-Cd for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2019 19:17:03 +0000 Received: by mail-pg1-x541.google.com with SMTP id x10so2430658pgi.5 for ; Thu, 19 Sep 2019 12:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3dlQ6O4U4Y6iTe68DKUl7bDSDWocpATfaoQJw9GaTwA=; b=BEAvPSDMRYZ7psL5CsA0bF0/tyiZdL5Pj4Blz60FpJHTg9+O6iIVTQAikrSRVEtX50 jS+ZLqYWO7Qik2WlNNIa2T98BHbLrXnHn9ZZbAJZLxQlr2pVEQ/FMHv+QuOeQ+g4oBDZ 9aTq09z4U3DkpRkdfiJcMWFXho8VFmc6AFMn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3dlQ6O4U4Y6iTe68DKUl7bDSDWocpATfaoQJw9GaTwA=; b=JdYAFVrJaV/UjwFhtze9ueYO8mHWxl9v62tr/brMmrkUuI/3gQU6+VGHdy7XVFKM9V 7P/k/VA1hvtN4uo36cJeNvrsC66mMcRyfNYtiAH9IHYgY6bZmZcdGlgYYlK2oeOhJ8jf FznmkfhNt7ptzrSVqSlNzf1MX023AFBxA353Bq/6rgTvhUCUqIdVwz4YZJEveTFw3iNT JM2HK0sjLa8546j8Hz2ikwdFnFAW5Ayvm+lfs93+97QGut5En53ftiEI2foc4GkFdMbx ey9LzojaD0QHtYiMLJ83BIL4KJJLGCpyDi+bHMnJfBg2z/jYGh7ZH7r8AR9nIssEVIV1 qzBw== X-Gm-Message-State: APjAAAWHL5lOwJpNUnFBHC/Js2D15b1OxXueUlf5araJHvMNdsET+vvn mAZaZFDxPc82jHIECV563Tc61g== X-Google-Smtp-Source: APXvYqyw0vY+LzMWyvC/PtDI3LAIIJ38He/wxtDobfuFTls9VDxuKUu1wJ2FE63lnnsle4oR6+aIIg== X-Received: by 2002:a65:4002:: with SMTP id f2mr10770258pgp.447.1568920621694; Thu, 19 Sep 2019 12:17:01 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id a17sm11919735pfc.26.2019.09.19.12.17.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Sep 2019 12:17:00 -0700 (PDT) Date: Thu, 19 Sep 2019 12:16:59 -0700 From: Matthias Kaehlcke To: Leonard Crestez Subject: Re: [PATCH 3/8] PM / devfreq: Move more initialization before registration Message-ID: <20190919191659.GV133864@google.com> References: <59bd0d871fad520eb417ca46943fa7f86ef9186a.1568764439.git.leonard.crestez@nxp.com> <20190918232904.GP133864@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190919_121702_433951_9B4E6FF5 X-CRM114-Status: GOOD ( 26.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artur =?utf-8?B?xZp3aWdvxYQ=?= , Abel Vesa , Saravana Kannan , "linux-pm@vger.kernel.org" , Viresh Kumar , Krzysztof Kozlowski , Chanwoo Choi , Kyungmin Park , MyungJoo Ham , Alexandre Bailon , Georgi Djakov , "linux-arm-kernel@lists.infradead.org" , Jacky Bai Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 19, 2019 at 06:52:07PM +0000, Leonard Crestez wrote: > On 19.09.2019 02:29, Matthias Kaehlcke wrote: > > Hi Leonard, > > > > On Wed, Sep 18, 2019 at 03:18:22AM +0300, Leonard Crestez wrote: > >> In general it is a better to initialize an object before making it > >> accessible externally (through device_register). > >> > >> This make it possible to avoid relying on locking a partially > >> initialized object. > >> > >> Signed-off-by: Leonard Crestez > >> --- > >> drivers/devfreq/devfreq.c | 38 ++++++++++++++++++++------------------ > >> 1 file changed, 20 insertions(+), 18 deletions(-) > >> > >> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c > >> index a715f27f35fd..57a217fc92de 100644 > >> --- a/drivers/devfreq/devfreq.c > >> +++ b/drivers/devfreq/devfreq.c > >> @@ -589,10 +589,12 @@ static void devfreq_dev_release(struct device *dev) > >> > >> if (devfreq->profile->exit) > >> devfreq->profile->exit(devfreq->dev.parent); > >> > >> mutex_destroy(&devfreq->lock); > >> + kfree(devfreq->time_in_state); > >> + kfree(devfreq->trans_table); > >> kfree(devfreq); > >> } > >> > >> /** > >> * devfreq_add_device() - Add devfreq feature to the device > >> @@ -671,44 +673,43 @@ struct devfreq *devfreq_add_device(struct device *dev, > >> devfreq->max_freq = devfreq->scaling_max_freq; > >> > >> devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev); > >> atomic_set(&devfreq->suspend_count, 0); > >> > >> - dev_set_name(&devfreq->dev, "devfreq%d", > >> - atomic_inc_return(&devfreq_no)); > >> - err = device_register(&devfreq->dev); > >> - if (err) { > >> - mutex_unlock(&devfreq->lock); > >> - put_device(&devfreq->dev); > >> - goto err_out; > >> - } > >> - > >> - devfreq->trans_table = devm_kzalloc(&devfreq->dev, > >> + devfreq->trans_table = kzalloc( > >> array3_size(sizeof(unsigned int), > >> devfreq->profile->max_state, > >> devfreq->profile->max_state), > >> GFP_KERNEL); > >> if (!devfreq->trans_table) { > >> mutex_unlock(&devfreq->lock); > >> err = -ENOMEM; > >> - goto err_devfreq; > >> + goto err_dev; > >> } > >> > >> - devfreq->time_in_state = devm_kcalloc(&devfreq->dev, > >> - devfreq->profile->max_state, > >> - sizeof(unsigned long), > >> - GFP_KERNEL); > >> + devfreq->time_in_state = kcalloc(devfreq->profile->max_state, > >> + sizeof(unsigned long), > >> + GFP_KERNEL); > >> if (!devfreq->time_in_state) { > >> mutex_unlock(&devfreq->lock); > >> err = -ENOMEM; > >> - goto err_devfreq; > >> + goto err_dev; > >> } > >> > >> devfreq->last_stat_updated = jiffies; > >> > >> srcu_init_notifier_head(&devfreq->transition_notifier_list); > >> > >> + dev_set_name(&devfreq->dev, "devfreq%d", > >> + atomic_inc_return(&devfreq_no)); > >> + err = device_register(&devfreq->dev); > >> + if (err) { > >> + mutex_unlock(&devfreq->lock); > >> + put_device(&devfreq->dev); > >> + goto err_out; > > > > goto err_dev; > > > >> + } > >> + > >> mutex_unlock(&devfreq->lock); > >> > >> mutex_lock(&devfreq_list_lock); > >> > >> governor = try_then_request_governor(devfreq->governor_name); > >> @@ -734,14 +735,15 @@ struct devfreq *devfreq_add_device(struct device *dev, > >> > >> return devfreq; > >> > >> err_init: > >> mutex_unlock(&devfreq_list_lock); > >> -err_devfreq: > >> devfreq_remove_device(devfreq); > >> - devfreq = NULL; > >> + return ERR_PTR(err); > > > > The two return paths in the unwind part are unorthodox, but I > > see why they are needed. Maybe add an empty line between the two paths > > to make it a bit more evident that they are separate. > > Old code did "devfreq = NULL" just so that the later kfree did nothing. > There were already two unwind paths, it's just that the second one was > less obvious. I will add a comment. > > >> err_dev: > > > > This code path should include > > > > mutex_destroy(&devfreq->lock); > > > > That was already missing in the original code though. > > Yes, that would be a separate patch. > > > Actually with the later device registration the mutex could be > > initialized later and doesn't need to be held. This would > > obsolete the mutex_unlock() calls in the error paths > Next patch already removes mutex_lock before device_register (that's the > purpose of the cleanup). If you're suggesting to move mutex_init around > it's not clear what would be gained? As per my earlier reply to self: I didn't look at the next patch before writing this, it's all good, nothing to do here :) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel