From patchwork Tue Apr 24 22:35:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134202 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp121077lji; Tue, 24 Apr 2018 15:36:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Jt3d95g41iO61SCgp9SbzmyiO3LrnBtTJClNhRR4OCBY2gbKSfAM36miEQUjRsF2dTfBz X-Received: by 10.99.181.89 with SMTP id u25mr20962416pgo.302.1524609414307; Tue, 24 Apr 2018 15:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524609414; cv=none; d=google.com; s=arc-20160816; b=RC9lbV+IrrJ+ZTt5J6R0FJ1RWp5isyVlSAYYYp4Q0uTt3GaUyWQxhvqHS5txI7IGH5 hC0A6S5zoWtJOUn++PiKjwkNQbFqw2mnKeHZ5gPpL5efH9+TKp3uBl5f+AyQjRxAT2vQ suTghUfR7SelddEzKy2LcYZDjB4hk/Ea81ceBAF9fQCHqoMHeyUyCBNzjk7XcUAuyDHy S2aXFj37bE99sOXWmNHKTWEuGpHBab80Njk4S/CEPTNBaY/5ntE4tuqYnpaeo7IDgf72 poJFlTrwq1wJZSmpHNhruOkr9NpTt+l+2dUiK6QRZ7qyp3vvLijVOHliPSWiH6xY3oEJ WJtg== 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=sEw6fnSpIZzDYqn7LEpmqBuXp0kHLCC6bdGkB0q0NKg=; b=Kk6lQWb8ug6rKM3JD/7OTbhZgC1CaB4DLv5ZB5g6If0PKAwhnzaDoSJzTU8LYgIzB6 WDDH+ujkw7UwL4xo3+b/Y2/d9ojsoNtiRNIdUVxOgAaOWL0QOi/kommEfZX7l6zqO1hV 4VMsqnJ1eOmxHkijfW/WlGaPsxQTHvlZ+We0UQgJ583MFplZ8DbM479NogfBPfn+T06X y703ewwf06qQ6JZf8hCEexaE2uBR5GrrQFs8WyP4kSxfIQ6gxrpaTTkyMsj1hr53QoUg g2cvahcbKwnaeO/QVRAjkfM3nSqXE21dzcwJ54Iif8eZfmc0TIbRTLSiWlTmrhizRBnX 9d1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A6YLZ91t; 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 z5si13793862pfh.110.2018.04.24.15.36.54; Tue, 24 Apr 2018 15:36:54 -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=A6YLZ91t; 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 S1751247AbeDXWgw (ORCPT + 11 others); Tue, 24 Apr 2018 18:36:52 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34122 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751184AbeDXWf1 (ORCPT ); Tue, 24 Apr 2018 18:35:27 -0400 Received: by mail-pf0-f196.google.com with SMTP id a14so2946986pfi.1 for ; Tue, 24 Apr 2018 15:35:27 -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=sEw6fnSpIZzDYqn7LEpmqBuXp0kHLCC6bdGkB0q0NKg=; b=A6YLZ91tXeRQoKnwKwZFLcQXgI1oSSwcyK/Ufi1LKZQT/WCHvNAYf5EfCovvl+d+v9 66cqQfGuGZKHJ5gIGz4t/ZlzIAsBgPtTCAenDeWqjgtMgukBOR15gWoO/jirCWZldY5R ovHDLP0hNAHWo+Gu1Pl4oFf/8OuZrIJ2938S0= 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=sEw6fnSpIZzDYqn7LEpmqBuXp0kHLCC6bdGkB0q0NKg=; b=KCUSTvHHiKmhUx0mtXyXk2nEQ1OOQ1Zn589Fyo/l4q9dy9qrlpR+XjC2N08RngcDlp zhjwRoc/eVRSg+IPp6vUgg02BmHt0A8EFPopsI8e6TGmd7WKlvaYvLmPl/5jHPqV/iot FpvoUSFSdLzTTGBYNuk/Z2AIJnr6qGloIJVR1+7ngjlflyIlhnf6hzdY0MFdF6eYihuM 82PuHQVWP6a+8VW7uhr/GZzTYBPeMHnNxcqFTIfKkJ6SIfP+b5iJCKCE93BxSbZ2bYR0 uYraifX4JKNQ6uExfmnM7kxO1/05WOOuE+/rQ410IU/1mToALnUZhm8ZYkHQsI6rOrU7 d0Ug== X-Gm-Message-State: ALQs6tBt4oThPiVgUYhqMOwzi3+ztKrTCUoVDwga7n8h4+bNQ1XIcEvu cBEbMD81JxqGjThI/U8VkyfeXA== X-Received: by 10.98.100.11 with SMTP id y11mr22216411pfb.118.1524609326918; Tue, 24 Apr 2018 15:35:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 15:35:26 -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 2/6] PM / devfreq: Use the device release function for cleanup Date: Tue, 24 Apr 2018 15:35:17 -0700 Message-Id: <20180424223521.28193-3-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 Removing the devfreq from the devfreq_list before calling unregister causes the device's release function to not find the devfreq and as such bails from the release function, resulting in the following log entries if an invalid governor is specified. ufshcd-qcom 624000.ufshc: devfreq_add_device: Unable to find governor for the device devfreq devfreq0: releasing devfreq which doesn't exist Drop the removal of devfreq from the list. As the release function will end by freeing the devfreq context we have to skip the freeing of this in our error handler, and hence need to pull in the device_unregister() calls. Signed-off-by: Bjorn Andersson --- drivers/devfreq/devfreq.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) -- 2.16.2 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 30a672397ff0..d5b278b8f20e 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -647,8 +647,10 @@ struct devfreq *devfreq_add_device(struct device *dev, if (IS_ERR(governor)) { dev_err(dev, "%s: Unable to find governor for the device\n", __func__); + mutex_unlock(&devfreq_list_lock); + device_unregister(&devfreq->dev); err = PTR_ERR(governor); - goto err_init; + goto err_out; } devfreq->governor = governor; @@ -657,17 +659,14 @@ struct devfreq *devfreq_add_device(struct device *dev, if (err) { dev_err(dev, "%s: Unable to start governor for the device\n", __func__); - goto err_init; + mutex_unlock(&devfreq_list_lock); + device_unregister(&devfreq->dev); + goto err_out; } mutex_unlock(&devfreq_list_lock); return devfreq; -err_init: - list_del(&devfreq->node); - mutex_unlock(&devfreq_list_lock); - - device_unregister(&devfreq->dev); err_dev: mutex_destroy(&devfreq->lock); kfree(devfreq); 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); From patchwork Tue Apr 24 22:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134200 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp120096lji; Tue, 24 Apr 2018 15:35:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx48iRoYE/gqAv2UzdcGEi4mPhL28tB7Xf2xBRzG3i2tDISt0f4LvhX63WeKl59F7d9XscSxP X-Received: by 10.99.0.4 with SMTP id 4mr21354146pga.107.1524609342713; Tue, 24 Apr 2018 15:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524609342; cv=none; d=google.com; s=arc-20160816; b=GGlKgQwkxyEyQyav6gTx4Qw3pxuvaR0PJE8ycjs4ak3FBr/Xhb/V31bpxHeyALL58R iuc5k3IxOexOdyT9SO7lelOGhqyrjB1+6T8CHg535uAp+xSvJk4tKtH8DwwS8j4BFKZE RCXtvmw2hamZVEJitkII59aVyBlfRl6x3aQUu2lqg4HgjmZLMxYyzf+anR+RChDXAj+1 WOG44ppua0gnf/kMMyQ4FvwdRNxJyWCa+/YXAz16AsZhgMuByRokuMwKK0JreJsm+Spy S4sOurntbA897TRYVQtsEH/VwkxbAPHDRFy7kElb/GDLdxex4U+Rns4RuJAJoAIMTU/s qV3w== 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=D4OT7Y7CTOdU0C5+C/yDyyFAxnnx7PGIHj0a+tQZEDk=; b=IkfWqZWGAQHWfC6KzMNNh2zC5SFDKLcbxnzBEON7CyzyAnlvFQYjzQKjQUmD5UwMJ+ Xk1zLwxLYnozMSQOd5/J38CkdUjcgVXyBp/gwPMUA9wyWuDJD0Jw5M86bWcmhuB/8SkP Jsas1Dg+NLJpsZgu0Nc258E9uET/kC6cbwqtZrZFQt2/JdjEpCkjUi12KxNs5sctZsxs Yob9t/D1JtfwgkB60lSkOLxzSF1JFWaAYcQ4o4CDPhpdSK69Sz2WvDKUlbFBwrNKU6lo lXEbSPtXdoatyi6faB6/JqZ7J6ZAceiUA2/4fSXV19lFdiFyN+84TTv2dwCjTE7Pumic yR/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aq+9Brm1; 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.42; Tue, 24 Apr 2018 15:35:42 -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=Aq+9Brm1; 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 S1751236AbeDXWfi (ORCPT + 11 others); Tue, 24 Apr 2018 18:35:38 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34124 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751242AbeDXWf3 (ORCPT ); Tue, 24 Apr 2018 18:35:29 -0400 Received: by mail-pf0-f194.google.com with SMTP id a14so2947043pfi.1 for ; Tue, 24 Apr 2018 15:35:29 -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=D4OT7Y7CTOdU0C5+C/yDyyFAxnnx7PGIHj0a+tQZEDk=; b=Aq+9Brm1w6a+/qTv8Uygkx8qLfM6YQhxPbupK1ThgB4YGybkxFqmE4AVjv2VY0VcPY Nn4YcSp7eedZ8b5+TygF0g5j+jJLieoCf28qErxmX1uP/b6bd6GvYXx9lrydzbVekVbP ACzK26oEWEGgfTM+gUs2KmUjC4rQkTzoalEIE= 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=D4OT7Y7CTOdU0C5+C/yDyyFAxnnx7PGIHj0a+tQZEDk=; b=tw0sHLdoyC0wodRf1i3cyNA5X8g6rhnvsvaY099bYmPpfu2lygU+jlK/Nzu5VLB7SC LLCoeCVoaNuQLVcLJg/OhtunbPlKEUrG+CWIIlr/SfPEPY/Vx7U9sYg4s0U5KGhL5+1X sFsAs9p1m/CSVcWJb2GJfEsL3jnVH+ot7mF2Cb/nS8vExGW+JJVlu0e38ywb0/kY1U1h ChQnBv1esA7Orvq5Orvzlql0+iQ7CH2wlITGOgXpePncHdjHr03DsL+MWoXV9VFdyUWb PTEXfWWk8g11j64UZChOcMGDWejqykAGP+/mjO0/86yXACTlYLTbe2wjSBymLCEJcgF7 VpEA== X-Gm-Message-State: ALQs6tBaPc6TKMHbAulxTaSs39QCz8Pzsc741SiOcHknGkMAol26aCg9 iauFLmDnvvr83OLnhi40Je2JdQ== X-Received: by 10.101.68.129 with SMTP id l1mr21777630pgq.239.1524609328938; Tue, 24 Apr 2018 15:35:28 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 15:35:28 -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 4/6] PM / devfreq: Remove unnecessary locking Date: Tue, 24 Apr 2018 15:35:19 -0700 Message-Id: <20180424223521.28193-5-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 prevent concurrent access to the devfreq object, but as all operations leading up to the registration of the devfreq device are local to devfreq_add_device() there's no reason to hold the lock. Signed-off-by: Bjorn Andersson --- drivers/devfreq/devfreq.c | 8 -------- 1 file changed, 8 deletions(-) -- 2.16.2 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 2e50f5d9d92a..70588dc2032c 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -584,7 +584,6 @@ struct devfreq *devfreq_add_device(struct device *dev, } mutex_init(&devfreq->lock); - mutex_lock(&devfreq->lock); devfreq->dev.parent = dev; devfreq->dev.class = devfreq_class; devfreq->dev.release = devfreq_dev_release; @@ -596,16 +595,13 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->nb.notifier_call = devfreq_notifier_call; if (!devfreq->profile->max_state && !devfreq->profile->freq_table) { - mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); if (err < 0) goto err_dev; - mutex_lock(&devfreq->lock); } devfreq->min_freq = find_available_min_freq(devfreq); if (!devfreq->min_freq) { - mutex_unlock(&devfreq->lock); err = -EINVAL; goto err_dev; } @@ -613,7 +609,6 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->max_freq = find_available_max_freq(devfreq); if (!devfreq->max_freq) { - mutex_unlock(&devfreq->lock); err = -EINVAL; goto err_dev; } @@ -635,12 +630,9 @@ struct devfreq *devfreq_add_device(struct device *dev, atomic_inc_return(&devfreq_no)); err = device_register(&devfreq->dev); if (err) { - mutex_unlock(&devfreq->lock); goto err_dev; } - mutex_unlock(&devfreq->lock); - mutex_lock(&devfreq_list_lock); list_add(&devfreq->node, &devfreq_list); From patchwork Tue Apr 24 22:35:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134199 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp120083lji; Tue, 24 Apr 2018 15:35:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+w44h4bwgR3LzA0ptIfqqmpDaeKxijMAX8xXs6Rs/qQFKoMU5aczt3QpidT+jx3+AUPczV X-Received: by 10.98.0.194 with SMTP id 185mr21795006pfa.238.1524609342380; Tue, 24 Apr 2018 15:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524609342; cv=none; d=google.com; s=arc-20160816; b=eY27tH8wRwzN8P20R4WcVuwOWWoVtmTd9+/TWl3Tq8kklyrcGAdrkRK1xJWmOEY7Wc 48a3h+KMfFspMCIHBYcCZYk9MkyVj9UWITjIP1UwH8Pwus9ztJxaqXRNYdrOdMvh9mZY KGNLxdoRPl/umL4GfEyjrjqGoPe+aQiL5CYgs3/PNGFMcLu9VXdeK8Y4sk2F6aBVV0dE Sahq4SyH9WnnuHUsL7NVy1FOHEhdi6382fS7wbOxdzha9NppOKAYnXKda1G0n4BdLU/r G8tpKGKFPN8Xpn0CBrz6TIvtf9B8ZpojDrG+mjkR4/jmz1vYeeTMCAAzX0TCCngySeZ9 CZ/w== 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=Iw/e9HslE9jUTacks1ilgfzwYVGUzkpbC8Ek7NEQYsc=; b=FfWKXC3g3wUF421GMcFDB+sk3iAe1RHAnNuQYSrMM/gKCwyMSp3CJLzO4DjuNoxMg7 +nWcHkLn3pt4+4rnLgWP+5nDSWzQx9JCOIjLY0ajYDJwb0j91JAfnNy9Aduj7zWChKJs m6vOhLF+t98kX1F8SCvP4dhT6JdRPWrABzO9Kbo5x2KY56hijrL4Kryw31yT1u3SVYr7 vZ9SkAiNqMvZ2abY4wmDNLPlyWGEwmHio7ZlGIrWAQIvNvQMJ+6aG7aFDVZFt0U2hObD qRP6LVwmbYnxL1T5F54BOywNRNaCMOoOHRAZVnqUhsxjf14t10+1jTfQXughMpr/sox0 X02w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MAnBBLg1; 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.41; Tue, 24 Apr 2018 15:35:42 -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=MAnBBLg1; 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 S1750779AbeDXWfh (ORCPT + 11 others); Tue, 24 Apr 2018 18:35:37 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:38405 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbeDXWfa (ORCPT ); Tue, 24 Apr 2018 18:35:30 -0400 Received: by mail-pf0-f193.google.com with SMTP id o76so8746390pfi.5 for ; Tue, 24 Apr 2018 15:35:30 -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=Iw/e9HslE9jUTacks1ilgfzwYVGUzkpbC8Ek7NEQYsc=; b=MAnBBLg1wEtC8DIL0y6G4A1aQDzi9IBhgC047BPZTIPaRuDnQtXcdTUmCYJmRaQ/B8 TBzjwKnCi5+hKZKIX9tQoemjCTb6w24Zpt8w1x6fxrS1xuZoghrPe29P7K9DE+DSSfqw 5/vMQ+2kR2SqFF0DAFTv06bZ8wob5qETllrB4= 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=Iw/e9HslE9jUTacks1ilgfzwYVGUzkpbC8Ek7NEQYsc=; b=hP4B3fP9ecjypvWMsXpjaKYsKuIY+Q3g2Dn43K0go/L9tRZBxTBvBU1AvhcW6CfzxK 3Iv2/BE+ebf+0vWNko5LQd6zI/n29d0wy3kA6tOKcNpZcFIIaXFtNWeBiTIn33YudBfP kUh75ZKtDA7RCcXWTYGPlyrrcA0Qqs/B0pVWMTkeR+ygHU8Tstj7AhMDWBoCxDdcpUC7 69vVqfws1ulgOuXe6oN6fyuITwF8yn//u9GOkis1hZ7CE6olaX2YyKn1qEbkwn/Yjp+9 58wnOpv2iKCu1EH4CIeix1rcxE0xMZ5aPozenuw1vGJuhNns6HAuw84jF+aKe4TIDYD1 Xllw== X-Gm-Message-State: ALQs6tAhd5J/LNOfh740uQI/Kx27kLTPC65TVgykS7Ea2YdvMH3XEZcg DW0bG5ocFht1KD7cggAcu93RabBNlBY= X-Received: by 10.101.97.72 with SMTP id o8mr21990478pgv.120.1524609330167; Tue, 24 Apr 2018 15:35:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 15:35:29 -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 5/6] PM / devfreq: Use put_device() on device_register error Date: Tue, 24 Apr 2018 15:35:20 -0700 Message-Id: <20180424223521.28193-6-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 After calling device_register() the dev must be released using put_device() rather than just freeing the carrying object. The release function of the devfreq device will be called in this case, but as we're yet to add the devfreq instance to the devfreq_list the release function would print a warning and return. But as the error path of devfreq_add_device() has been cleaned up the release function is now the only function taking the devfreq off the list, so we do not need to safe guard against the devfreq not being on the list. Signed-off-by: Bjorn Andersson --- drivers/devfreq/devfreq.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) -- 2.16.2 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 70588dc2032c..c804bd72a644 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -523,11 +523,6 @@ static void devfreq_dev_release(struct device *dev) struct devfreq *devfreq = to_devfreq(dev); mutex_lock(&devfreq_list_lock); - if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) { - mutex_unlock(&devfreq_list_lock); - dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n"); - return; - } list_del(&devfreq->node); mutex_unlock(&devfreq_list_lock); @@ -583,6 +578,7 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_out; } + INIT_LIST_HEAD(&devfreq->node); mutex_init(&devfreq->lock); devfreq->dev.parent = dev; devfreq->dev.class = devfreq_class; @@ -630,7 +626,8 @@ struct devfreq *devfreq_add_device(struct device *dev, atomic_inc_return(&devfreq_no)); err = device_register(&devfreq->dev); if (err) { - goto err_dev; + put_device(&devfreq->dev); + goto err_out; } mutex_lock(&devfreq_list_lock);