From patchwork Thu Mar 7 11:21:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 159841 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7311952jad; Thu, 7 Mar 2019 03:21:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzNNy6Sq2MYN9GXzCKIXrPDMdJYiUFpPkmrY0aTpSiaxlakBtbOoXWl2LJ7aQkusS9fiW/U X-Received: by 2002:a65:628f:: with SMTP id f15mr11026205pgv.410.1551957708654; Thu, 07 Mar 2019 03:21:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551957708; cv=none; d=google.com; s=arc-20160816; b=w2c60hG3MCBn+DgTSEMMPPT5KcFmr0Y9thgORFsLfNX3EDj/IxsTOf+Ku1/MbPdgJc yi7OWtsEFGmGkPJ8eTXyoyu1vibjRKAz95HJexItfJcEV+tbUZdHIC4gmLwNKXoZbU1G 7RvSoJaCuX6BLwbKAG8uWMQ809ZG0b1/27TUMZ09vU/nY64cNw+QaDJixDkMWpRGEllw HT9uOgMbqPOuD6/LVUB22dalWSpav/CITSALD6mkDUoGSrUj91aXqar+PH1ZMJrlxEga ZKdtkdP+vfxG90sjrz0YnNrqqMXg/KKsSAVnMfvDdCZrXaScxC5j1t9rjcRmobQ/64Nc 9BtQ== 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=5tEHKfvnXNfKwrdF5aDWPo1P8shvTzqe2wb5KzoFAow=; b=CGVnjDY8kAnrp7COotSymVEYpsBQ1vmj4fwEXchMz4uqIMqhsB8FS02i+yiSDpY12p AAuHy1Ibv0oVwaTDdKBPBMezN6Bl1riQivz93R8y70e6UzDnawN+5iJ2CvDB/D3sk00A FgmaKmSs/mdSM7b8cGjM44GG42UXgRguRLy8Qqua5EF5AnY8RwuYtr0YFbe7BrvX36D7 Bh40Z1cFiGLIBBGE4rbf+EfbCFN3FjFdhGg8w903vkLNCnn/rCEeZdOer78Vjz113aSK dPxg6x0M/r1C+naH/SAWDuXE8nH6pOuej2sOxHlbe8tKlAxoRUxB0alN5S9cGD/yGegK XviA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RAfltdKl; 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 l184si3788507pgd.50.2019.03.07.03.21.48; Thu, 07 Mar 2019 03:21:48 -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=RAfltdKl; 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 S1726197AbfCGLVr (ORCPT + 11 others); Thu, 7 Mar 2019 06:21:47 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38138 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726057AbfCGLVr (ORCPT ); Thu, 7 Mar 2019 06:21:47 -0500 Received: by mail-pf1-f194.google.com with SMTP id n125so11182292pfn.5 for ; Thu, 07 Mar 2019 03:21:46 -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=5tEHKfvnXNfKwrdF5aDWPo1P8shvTzqe2wb5KzoFAow=; b=RAfltdKlHGHZ+JHjvoQ4AIKnbEXg/et9PZH9EsjuGVn9QNnonZlrSlrCYGywetXTzi DDudSMXNNcuLY7+9nBDDoopGm6P+MXGNKmxWBLbA/DYumWnEC+yBd2wqvI8IcjvkC5B4 WF/8o8684ooap+Nh5geAWe8PvOMW6/vRlRJVb6mbzshtVO7xndDU+75/wiS3HGIBGqJ2 XSRoiPoYAxsV3cnifj6h5NydXsmmbxlVIhAmvCMbaEH2KW3s+YoeS/PyWFSslICfPq19 G5blOkvBauHN4nXS504wTVc8JOZ8Lgp2yrxkBB77DtIhQkmNm3GwqXj8MdOE5dOGES3/ jJxg== 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=5tEHKfvnXNfKwrdF5aDWPo1P8shvTzqe2wb5KzoFAow=; b=Aq6/lLzQXP1IHS4Fzh9QZBcqVQHu8xTG/vIIroAw+AC+4CbcH2bG1xOcciSPy4jXrX q9Nuxr62I/eTtceW7jhOWhJ7Cevsds/MWathZilozQCBk4McA4KBUkTpMY4LBkXEuFI/ rvF9XeLYTa2ORQ1eQKimWFN7fhh0ZT/BdsZUj7HkoXgKQiT3ruqEmhy/2ypH7wW9eCNi Q+YgJxniFcKyD7UkkoErTvYDXAsAotXV3jmw7b2tD1rdJsfUQ/iqFtLltbBP/WEroY4m C32A1vhVyjk1q8LYQV9KSvtoWrh4OOTf2HcRde8/Ue7qapRG87OWt4ght+x0gCTjVw8L Iluw== X-Gm-Message-State: APjAAAWOleNCqwvsYR+lRQIpEYaFWL90OaxJSxPs4XkQU2c9ExDGUCuf aO/LtqltotqbzIX6rvvy6v8mwQ== X-Received: by 2002:a17:902:7615:: with SMTP id k21mr12605890pll.152.1551957706321; Thu, 07 Mar 2019 03:21:46 -0800 (PST) Received: from localhost ([122.171.71.18]) by smtp.gmail.com with ESMTPSA id l28sm11646602pfi.186.2019.03.07.03.21.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 03:21:45 -0800 (PST) From: Viresh Kumar To: "4 . 11+" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH 4.11+] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Thu, 7 Mar 2019 16:51:41 +0530 Message-Id: <2fe3a119ea8fccd301677b43b585925abf7217af.1551957675.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org commit 625c85a62cb7d3c79f6e16de3cfa972033658250 upstream. 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. Cc: 4.11+ # 4.11+ Reported-by: Donghee Han Reported-by: Sangkyu Kim Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- This needs to be applied from v4.11 to v4.17 (including both). --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 18 +++++++++--------- include/linux/cpufreq.h | 12 ++---------- 3 files changed, 14 insertions(+), 22 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 0e3f6496524d..698e8e053fc8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -528,13 +528,13 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq); * 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 283491f742d3..83cefd267feb 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1042,7 +1042,7 @@ static void intel_pstate_debug_hide_params(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); \ } @@ -1051,7 +1051,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; @@ -1062,7 +1062,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); @@ -1076,7 +1076,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; @@ -1102,7 +1102,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; @@ -1123,7 +1123,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; @@ -1145,7 +1145,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; @@ -1183,7 +1183,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; @@ -1217,7 +1217,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; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 87165f06a307..36d157552540 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -238,20 +238,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)