From patchwork Fri Jan 25 07:23:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 156555 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp34171jaa; Thu, 24 Jan 2019 23:23:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN4+ElctiiV2ZZeM8wptx1q2GJoS7byxtLuDSLo2SvD4H9g9SV+gSyEUijxLJEVVZY/Kgpta X-Received: by 2002:a62:5793:: with SMTP id i19mr9909590pfj.49.1548401000378; Thu, 24 Jan 2019 23:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548401000; cv=none; d=google.com; s=arc-20160816; b=bEdaZ+0q6iIZj/s75Vztku73M75xB4lT8d7GIYkV6A3NDCCG7wk52ujl+qnorxA0XQ TP+LvhuuQDuU0JFGYhWuVFyQP0IeUg3r4mcNvSXGyoDqrvJrC1Soj8R286piVAIsRT0I /XsLeQpowXbLXlM5i3tU5X5Y66nvcm2FQL53kwbMW8Q0lfsuAufhmeLn856KKwtA92Xy cMJniq8Ub9Lqp5XzEM5qWU+rsCVyOlkkBnJDJ4aNIxeexeISIW9k6KbYEKcaqTMUSta6 KOhl5kqY4ieFaswglRr6Sv2e2xMFxAx8SE6P/kQNP4BwHLYTbsv1kYULCPhXeHcwYm9C 4HKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CkUxUp9XSiXVv+IqUvYd9qbsEyKgL+k5fCT93eAcUk0=; b=Yd4oqFH/bGCPgYUailbd7QASVN4phNhsgHddk0GXunmeDEo6mJ1yG6f/VeFhindoEk +ZA90eIkpDQI54GyoebOG5o65arxGIZMhbbiiflX0OayaSleR23QqAXxNOWQ1irj8If0 M0p1kDG5FvKPOMEnXqQ4Bx7Afs/EPgwlqFSQFuZK369t1u1nqSI9mCSZaPXUqVLR53Dv ScI6GorrqykdimdGULaxIpZy8GT1gE2rgJ111IUKTH6XSl1nF36nzaIHXuafZsbJaMOH FnSE8hG9BGbN0F5xLjjkm+OkAZG1OqDJsMTEX1kFH6CgjVoG9DUuuRYUcpp1/Rzne1UM HEDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFGn+VeP; 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 j22si22995869pfi.252.2019.01.24.23.23.19; Thu, 24 Jan 2019 23:23:20 -0800 (PST) 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=CFGn+VeP; 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 S1726817AbfAYHXT (ORCPT + 11 others); Fri, 25 Jan 2019 02:23:19 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39929 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfAYHXT (ORCPT ); Fri, 25 Jan 2019 02:23:19 -0500 Received: by mail-pf1-f195.google.com with SMTP id r136so4338495pfc.6 for ; Thu, 24 Jan 2019 23:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CkUxUp9XSiXVv+IqUvYd9qbsEyKgL+k5fCT93eAcUk0=; b=CFGn+VePdgBy4Wx6e+t1Tkz2jiE6OaJrpUoOvTnEDa7luPuDkJq0J+Yru9j8wQDpmP iXPkT23/+yL3Cc04F7LtjYBMBFhW97VlWgK1Wq7krLAma6KTqXUhB5JzJLVUazcenEc0 IE0sCePEPf9rXf+4VeWsSvMrjbiphXzoOYnQg= 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:mime-version :content-transfer-encoding; bh=CkUxUp9XSiXVv+IqUvYd9qbsEyKgL+k5fCT93eAcUk0=; b=V9CtM/kAreVaA/WXPKREUvOvtK/xqFJ5yeCPLwbaFv4P17y8JrbPap4oI7xQKvfJOJ JKEgRWzL/biIei7Qh6OH7DKvUTi7YTeWevAnfswgUZ3rOEUCUxIZeFah1wzSwWTbsNlO 2f2CzvBuoNJiMIoPbewsIgoPnSAUGeeacPNAq3Oh0QAHa6UvclSwMF31E8+LC6mK9ozY 4iGgtl4bxxizPbmq/qoRGdba3L+ILBgEQbWuXgvPGVElFnP643tv13MUWUiQ9tJpi8V5 bezCQQguv2aY/0zYR4v9GjP/D1V6pesvdq72Xq+YHqRGbdG6uBgZwtYILrbXe7I9IRMD At4g== X-Gm-Message-State: AJcUuke1rWCdfk7FX/bEkbl7CHaAFGUUH7Wqh8y7z7ApRGwMYq86Ycwq /ktG/s7nx1IxZz8HrkB8HVAmqg== X-Received: by 2002:a63:7d06:: with SMTP id y6mr8880983pgc.171.1548400997816; Thu, 24 Jan 2019 23:23:17 -0800 (PST) Received: from localhost ([122.172.102.63]) by smtp.gmail.com with ESMTPSA id d3sm27569641pgl.64.2019.01.24.23.23.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 23:23:16 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Srinivas Pandruvada , Len Brown Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Donghee Han , Sangkyu Kim , linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Fri, 25 Jan 2019 12:53:07 +0530 Message-Id: <3a0a3ec5b36380deb59797f7189dbd0548828cf8.1548400979.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce00 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The cpufreq_global_kobject is created using kobject_create_and_add() helper, which assigns the kobj_type as dynamic_kobj_ktype and show/store routines are set to kobj_attr_show() and kobj_attr_store(). These routines pass struct kobj_attribute as an argument to the show/store callbacks. But all the cpufreq files created using the cpufreq_global_kobject expect the argument to be of type struct attribute. Things work fine currently as no one accesses the "attr" argument. We may not see issues even if the argument is used, as struct kobj_attribute has struct attribute as its first element and so they will both get same address. But this is logically incorrect and we should rather use struct kobj_attribute instead of struct global_attr in the cpufreq core and drivers and the show/store callbacks should take struct kobj_attribute as argument instead. This bug is caught using CFI CLANG builds in android kernel which catches mismatch in function prototypes for such callbacks. Reported-by: Donghee Han Reported-by: Sangkyu Kim Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 23 ++++++++++++----------- include/linux/cpufreq.h | 12 ++---------- 3 files changed, 17 insertions(+), 24 deletions(-) -- 2.20.1.321.g9e740568ce00 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e35a886e00bc..ef0e33e21b98 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -545,13 +545,13 @@ EXPORT_SYMBOL_GPL(cpufreq_policy_transition_delay_us); * SYSFS INTERFACE * *********************************************************************/ static ssize_t show_boost(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); } -static ssize_t store_boost(struct kobject *kobj, struct attribute *attr, - const char *buf, size_t count) +static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) { int ret, enable; diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index dd66decf2087..5ab6a4fe93aa 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -895,7 +895,7 @@ static void intel_pstate_update_policies(void) /************************** sysfs begin ************************/ #define show_one(file_name, object) \ static ssize_t show_##file_name \ - (struct kobject *kobj, struct attribute *attr, char *buf) \ + (struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ { \ return sprintf(buf, "%u\n", global.object); \ } @@ -904,7 +904,7 @@ static ssize_t intel_pstate_show_status(char *buf); static int intel_pstate_update_status(const char *buf, size_t size); static ssize_t show_status(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { ssize_t ret; @@ -915,7 +915,7 @@ static ssize_t show_status(struct kobject *kobj, return ret; } -static ssize_t store_status(struct kobject *a, struct attribute *b, +static ssize_t store_status(struct kobject *a, struct kobj_attribute *b, const char *buf, size_t count) { char *p = memchr(buf, '\n', count); @@ -929,7 +929,7 @@ static ssize_t store_status(struct kobject *a, struct attribute *b, } static ssize_t show_turbo_pct(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { struct cpudata *cpu; int total, no_turbo, turbo_pct; @@ -955,7 +955,7 @@ static ssize_t show_turbo_pct(struct kobject *kobj, } static ssize_t show_num_pstates(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { struct cpudata *cpu; int total; @@ -976,7 +976,7 @@ static ssize_t show_num_pstates(struct kobject *kobj, } static ssize_t show_no_turbo(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { ssize_t ret; @@ -998,7 +998,7 @@ static ssize_t show_no_turbo(struct kobject *kobj, return ret; } -static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, +static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b, const char *buf, size_t count) { unsigned int input; @@ -1045,7 +1045,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, return count; } -static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, +static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b, const char *buf, size_t count) { unsigned int input; @@ -1075,7 +1075,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, return count; } -static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, +static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b, const char *buf, size_t count) { unsigned int input; @@ -1107,12 +1107,13 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, } static ssize_t show_hwp_dynamic_boost(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u\n", hwp_boost); } -static ssize_t store_hwp_dynamic_boost(struct kobject *a, struct attribute *b, +static ssize_t store_hwp_dynamic_boost(struct kobject *a, + struct kobj_attribute *b, const char *buf, size_t count) { unsigned int input; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index c86d6d8bdfed..0b427d5df0fe 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -254,20 +254,12 @@ __ATTR(_name, 0644, show_##_name, store_##_name) static struct freq_attr _name = \ __ATTR(_name, 0200, NULL, store_##_name) -struct global_attr { - struct attribute attr; - ssize_t (*show)(struct kobject *kobj, - struct attribute *attr, char *buf); - ssize_t (*store)(struct kobject *a, struct attribute *b, - const char *c, size_t count); -}; - #define define_one_global_ro(_name) \ -static struct global_attr _name = \ +static struct kobj_attribute _name = \ __ATTR(_name, 0444, show_##_name, NULL) #define define_one_global_rw(_name) \ -static struct global_attr _name = \ +static struct kobj_attribute _name = \ __ATTR(_name, 0644, show_##_name, store_##_name)