From patchwork Wed Dec 10 04:15:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42085 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6D5F526C6B for ; Wed, 10 Dec 2014 04:16:26 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id y19sf1408192wgg.3 for ; Tue, 09 Dec 2014 20:16:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=1pYxt0bbQhyI6R/CtS4Lre7EmQ3Aqory2c4iwB0b5LE=; b=M1i0xyAm5Hg0FHqTytYtFfQl9Wj+bJ/9NtKUnhTIt91/g3rWWLKoFUVDFCqewL9Hm9 b5yjrIm418N3WKWBfPChwI4IJd+ef1YWL8h/4dI5FaixcyEfdJcPFEQNSOoI5KNd/Pti 6TYLYJqnvSPsaQqEx8eJmmJYEk8lRrKwQiGB23SRfM4gXU8PZACJDS5lDB0vaE8NJ/2X nt5zwdfNUOp6QeBoEUehS24e4CuK+5r0fA+Z1ta8ajuIKndlejnQW8H9+qqHsEz0zvJG YIXr+o19q8zq2X5NgLPejqWSUcOgu70w+oFmTg2/wSsxFVX3bO0EjpY+4vP9f65s3Sez folA== X-Gm-Message-State: ALoCoQl2XUrdMQkMo2ZEbS/isPJifTJ5sfCs16h+btwqDyJ3sJTbMtgytt9juArwY8bgVb1GIU5o X-Received: by 10.152.170.201 with SMTP id ao9mr19387lac.5.1418184985678; Tue, 09 Dec 2014 20:16:25 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.39 with SMTP id j7ls123481laf.92.gmail; Tue, 09 Dec 2014 20:16:25 -0800 (PST) X-Received: by 10.112.45.228 with SMTP id q4mr1822101lbm.35.1418184985364; Tue, 09 Dec 2014 20:16:25 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id s4si1253372lag.91.2014.12.09.20.16.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 20:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id p9so1683609lbv.28 for ; Tue, 09 Dec 2014 20:16:25 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr1848536lbc.66.1418184985281; Tue, 09 Dec 2014 20:16:25 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp834709lbc; Tue, 9 Dec 2014 20:16:24 -0800 (PST) X-Received: by 10.68.189.136 with SMTP id gi8mr3549896pbc.54.1418184982904; Tue, 09 Dec 2014 20:16:22 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ei12si4749825pdb.165.2014.12.09.20.16.22 for ; Tue, 09 Dec 2014 20:16:22 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755337AbaLJEQV (ORCPT + 12 others); Tue, 9 Dec 2014 23:16:21 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:50270 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755310AbaLJEQV (ORCPT ); Tue, 9 Dec 2014 23:16:21 -0500 Received: by mail-pa0-f46.google.com with SMTP id lf10so1352845pab.33 for ; Tue, 09 Dec 2014 20:16:20 -0800 (PST) X-Received: by 10.66.119.70 with SMTP id ks6mr3443895pab.74.1418184980865; Tue, 09 Dec 2014 20:16:20 -0800 (PST) Received: from localhost ([122.166.92.172]) by mx.google.com with ESMTPSA id ut7sm2831797pbc.8.2014.12.09.20.16.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 09 Dec 2014 20:16:20 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar Subject: [PATCH 4/5] opp: handle allocation of device_opp in a separate routine Date: Wed, 10 Dec 2014 09:45:34 +0530 Message-Id: X-Mailer: git-send-email 2.2.0 In-Reply-To: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> References: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> In-Reply-To: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> References: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Get the 'device_opp' allocation code into a separate routine to keep only the necessary part in dev_pm_opp_add_dynamic(). Also do s/sizeof(struct device_opp)/sizeof(*dev_opp) and remove the print message on kzalloc() failure as checkpatch warns for that. Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 525ffb202d77..1150b9d2e012 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -386,6 +386,27 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); +static struct device_opp *add_device_opp(struct device *dev) +{ + struct device_opp *dev_opp; + + /* + * Allocate a new device OPP table. In the infrequent case where a new + * device is needed to be added, we pay this penalty. + */ + dev_opp = kzalloc(sizeof(*dev_opp), GFP_KERNEL); + if (!dev_opp) + return NULL; + + dev_opp->dev = dev; + srcu_init_notifier_head(&dev_opp->srcu_head); + INIT_LIST_HEAD(&dev_opp->opp_list); + + /* Secure the device list modification */ + list_add_rcu(&dev_opp->node, &dev_opp_list); + return dev_opp; +} + static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, unsigned long u_volt, bool dynamic) { @@ -412,27 +433,13 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, /* Check for existing list for 'dev' */ dev_opp = find_device_opp(dev); if (IS_ERR(dev_opp)) { - /* - * Allocate a new device OPP table. In the infrequent case - * where a new device is needed to be added, we pay this - * penalty. - */ - dev_opp = kzalloc(sizeof(struct device_opp), GFP_KERNEL); + dev_opp = add_device_opp(dev); if (!dev_opp) { mutex_unlock(&dev_opp_list_lock); kfree(new_opp); - dev_warn(dev, - "%s: Unable to create device OPP structure\n", - __func__); return -ENOMEM; } - dev_opp->dev = dev; - srcu_init_notifier_head(&dev_opp->srcu_head); - INIT_LIST_HEAD(&dev_opp->opp_list); - - /* Secure the device list modification */ - list_add_rcu(&dev_opp->node, &dev_opp_list); head = &dev_opp->opp_list; goto list_add; }