From patchwork Tue Apr 24 22:35:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 10361141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9006B60546 for ; Tue, 24 Apr 2018 22:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 784E228DCC for ; Tue, 24 Apr 2018 22:35:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C87428E3D; Tue, 24 Apr 2018 22:35:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9AB28E37 for ; Tue, 24 Apr 2018 22:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751247AbeDXWfb (ORCPT ); Tue, 24 Apr 2018 18:35:31 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40848 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbeDXWf2 (ORCPT ); Tue, 24 Apr 2018 18:35:28 -0400 Received: by mail-pf0-f194.google.com with SMTP id f189so4349236pfa.7 for ; Tue, 24 Apr 2018 15:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4ivdFJqZQ2sq/oYdvN+N5VLiGFPzB2vDUlRls76PKKo=; b=IFeIQJtK4RSICBMMLvrZE22MjnSww1o6K50AT6pwmkPA0eNhqtYy/ee0orkFnDvhuZ abEi+4pwtyw5UrYmAclRvrIvGqFcInhp+GLylNqK6OrIEvEfTjAnZdUswekRF5twsd9d +s7Ij4eSwnB3a3QyE6bKlYzf5vR7K3FlpcMvQ= 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:in-reply-to :references; bh=4ivdFJqZQ2sq/oYdvN+N5VLiGFPzB2vDUlRls76PKKo=; b=iwrtRsyg10PVOQ8xDfasx0Y7uSUzATxwNa2w1z6RGW6Xb9C0PGgAk6w7+MYPq7ccsl gJWqlz3BC7r+7jqsZpVagXNbLhbcJQRda06AtZVaM2+an0mx7TwFFFcho6N4v9tWeoHn GZnGz73GjYs0OjwpzzyqJ/j6WuFjxL+uk3enJnAmUVmwXrgudCxEb0+elBkl1rPQL6Lw /sMCuThBU0fldVPVrK75Vp0LCA8MkfYX1G4+Kqh+9M+5/PxuZL+UbsVPbIK0fQYirZxM I/sGdAT9cmiBEeXtkMxP5VhmGfdC4s8lYlqLtn8Q6gFN84ahUc19Fq4eDzaYhjpHO8bC +ruw== X-Gm-Message-State: ALQs6tAT8G9ZV/f+1Hq+7H6i4G4aMIoIk7JrC8yh2GbeI9WuexVTenv1 1ArDCfpG19UV90jY+SyPzHs73g== X-Google-Smtp-Source: AIpwx4+mC0LSTZl4mwf5prJdhFxm0W2cVTznBbofc86teaIZ7N8gvHo3lnO/N7fQ+rRnFLTTKK1s+g== X-Received: by 10.167.131.217 with SMTP id j25mr25222286pfn.5.1524609327905; Tue, 24 Apr 2018 15:35:27 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id w26sm35856621pfi.17.2018.04.24.15.35.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 15:35:27 -0700 (PDT) From: Bjorn Andersson To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] PM / devfreq: Reorder devfreq_add_device() Date: Tue, 24 Apr 2018 15:35:18 -0700 Message-Id: <20180424223521.28193-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180424223521.28193-1-bjorn.andersson@linaro.org> References: <20180424223521.28193-1-bjorn.andersson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The devfreq lock is used to ensure that the devfreq object is fully initialized before e.g. the sysfs interface is accessing it. Moving all these operations before the device_register() call ensures the same thing without a lock; as it's yet to be shared outside the current context. This allows us to simplify the locking done in devfreq_add_device(). Instead of using devres for trans_table and time_in_state we use the release function to free them as the devfreq device is released. Signed-off-by: Bjorn Andersson --- drivers/devfreq/devfreq.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index d5b278b8f20e..2e50f5d9d92a 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -539,6 +539,8 @@ static void devfreq_dev_release(struct device *dev) devfreq->profile->exit(devfreq->dev.parent); mutex_destroy(&devfreq->lock); + kfree(devfreq->time_in_state); + kfree(devfreq->trans_table); kfree(devfreq); } @@ -617,6 +619,18 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->scaling_max_freq = devfreq->max_freq; + devfreq->trans_table = kcalloc(devfreq->profile->max_state * + devfreq->profile->max_state, + sizeof(unsigned int), + GFP_KERNEL); + devfreq->time_in_state = kcalloc(devfreq->profile->max_state, + sizeof(unsigned long), + GFP_KERNEL); + + 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); @@ -625,19 +639,6 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_dev; } - devfreq->trans_table = devm_kzalloc(&devfreq->dev, - sizeof(unsigned int) * - devfreq->profile->max_state * - devfreq->profile->max_state, - GFP_KERNEL); - devfreq->time_in_state = devm_kzalloc(&devfreq->dev, - sizeof(unsigned long) * - devfreq->profile->max_state, - GFP_KERNEL); - devfreq->last_stat_updated = jiffies; - - srcu_init_notifier_head(&devfreq->transition_notifier_list); - mutex_unlock(&devfreq->lock); mutex_lock(&devfreq_list_lock); @@ -669,6 +670,8 @@ struct devfreq *devfreq_add_device(struct device *dev, err_dev: mutex_destroy(&devfreq->lock); + kfree(devfreq->time_in_state); + kfree(devfreq->trans_table); kfree(devfreq); err_out: return ERR_PTR(err);