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: 134198 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp120060lji; Tue, 24 Apr 2018 15:35:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpOqZHpBHwrYfnL4pZ4ERb8V5DwlVQrzDHLF6SWxmdSk3MLH3J/UdyF8pqjbp7xQEJBFhxH X-Received: by 10.101.76.130 with SMTP id m2mr1922924pgt.23.1524609341378; Tue, 24 Apr 2018 15:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524609341; cv=none; d=google.com; s=arc-20160816; b=cEcJ5fwKSN6cJ0xJQ7q2CwPOZOxgev05196mHOIrpHkQ6bRlyKcI9mmnIHvgSYNCoU 7TY7/zU94P4Sb62ecf8NGgTwz+5zHSM+FnFUgNl3rY8ToiSKngsWCtYV/nYzFORj3Foh NXRWyCv3YB7o9ryHLbD3LUwu0nCjJB2Rr8e7xPJe2ji7ct3OyLC7+fuM2w2WyjmFlbNc iH4bEgtAZfhdpKYYvgP1Y9MSQ4B6bQY/++pC62T+LMsp6XAYWKFAn2bjMMNUE86Eaoe6 Lq/M1FaGb7gJ/fWYAd3Y8qEJaWHQvUWkZbPv8qv7okuU4EHdKycYmC36jLrhwDoGWWfT lyTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4ivdFJqZQ2sq/oYdvN+N5VLiGFPzB2vDUlRls76PKKo=; b=HvbInuDZ3ToKTnnQ0J1ny+FS2L9ohlD2+FsdJ4d2m6ltvCjIF8DPE2hvWrmiT0NIfW +7AI9U52jCWWu790D7B99QuHR3jVccWwhoDC6dAg49ZHGlzLkQYz9P2jYwkc4W8eXiTU SiFHMb4hVxzYB/U0WmxZ5g2QV+EIcs5xG2vRvF2jUBobvQzT3JOZytjuMHUAamgulzm2 w2UHcV2GNxcpSxTRW5VvBSGBHNIai/83hktlCzSxWxJxfi/GlxuSpS8GaDWmxpLmE+HV u6RAQMwl3ipuGaRsn194ir2QOPkVgttZl0zQeuBhqxy6Mn4OGFgefvfsTZkug7Mj74Hu xBnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IFeIQJtK; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si12317959pgn.152.2018.04.24.15.35.40; Tue, 24 Apr 2018 15:35:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b=IFeIQJtK; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751247AbeDXWfb (ORCPT + 11 others); 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-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 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(-) -- 2.16.2 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);