From patchwork Thu Mar 7 11:20:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 159840 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7311285jad; Thu, 7 Mar 2019 03:21:06 -0800 (PST) X-Google-Smtp-Source: APXvYqzEM/bFcW/xhtotr/c4IDVgZHmpc5xTKy4Tva9EN1h46IT8LHy2ftWtGyEIHhwQbK3/kyA0 X-Received: by 2002:a63:ea52:: with SMTP id l18mr11012269pgk.317.1551957666222; Thu, 07 Mar 2019 03:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551957666; cv=none; d=google.com; s=arc-20160816; b=Ko4Ef7GL/LA+hz/2iqs0oyekk7ZAtthRq0pITAEYO6WBNkNzWbSCvNty/4T+dBhqPf PekuS8tJCnS/60/65EEyxe/RBQprrHOJ8t7GxtJ9TuDW3o/ICu+iJF8Vc7blu0UNOrTg 9B++LBdJeNXL/RRhqtZ9tuyLzrL+JTRB5Y18M3nPRjIlgm3GP67NOSSwdfRODV971LFs NuTUuaAn4SIEVRYkpMUuMD8uqLoOLOrY9uQ+aqfki1o01V0CJ+DS3gfyL1pt8KRLNwQr 1Hjin6mJIBazdjL1FHFGBiGuVBw+Mn96mdjw3pxdDPhdGiQ1AfQFSP02Kw/9wo2UgYNA qFtA== 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=l9FLh9mVEBSaTdBrhoB6HBxvMpgNJxmNszp2qjQYpFI=; b=SK06igbHHfQr9NtABMH22FvGLf0mcI/sD00MgBgpUjzL1VwkWOxK9L+UoE/HGg/V2V 6OcZfpxWDec65VN81VuQDf8cBC58RYwplI9k5eve+PUYS25vLCVjuRpuTmVexC8JfW6I MvhpsPEFm9e610y0wsK9Mhusaq+Tr5x7xJWCak5PADeJWhVPYwisayAdfKwxoovE435x oC3CKcdkVzAOQlZ54m6hxHD/cD8vtYlV5EHnBE8ianVTGQdL4fL3ltUs3KunoQtWweFA XgN9PRIJiprYI9zNgceIgFZX9tZGruREmjXxzAZN+JwxpVCl+cxQN3DbVaNTiAOtkJ/T 4tZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TgFfZyXz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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.05; Thu, 07 Mar 2019 03:21:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=TgFfZyXz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1726293AbfCGLVF (ORCPT + 14 others); Thu, 7 Mar 2019 06:21:05 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:32777 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfCGLVE (ORCPT ); Thu, 7 Mar 2019 06:21:04 -0500 Received: by mail-pg1-f195.google.com with SMTP id h11so11020069pgl.0 for ; Thu, 07 Mar 2019 03:21:03 -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=l9FLh9mVEBSaTdBrhoB6HBxvMpgNJxmNszp2qjQYpFI=; b=TgFfZyXzkCK5QcaQBaMgvOc2zn/8747mqY0v8aCD47bfrSnqVOC2bQhVmb5KNYLYw1 128uXpkhRNaqHQDQvE/T2zxKpap7FvT93j3Oyi5bB7WIfSxmKCm8OfL8cqthpcVw2Zxm 8B3tGR0KPx4RUlOjbmhS79fo4SxOhR9inLv2gLubVotxflzEaiHRpTWg24jBpHfnkRJI 7ItnItk+sl74dn2Vq80q0Vy3OfOY4CqZajvwpVVN6jX+DXBczGYWmxfg/rigPMHW6fK4 efuWl66BjgvtKkSaqZmJkehsdzHG5QPeq741b/ANgoEm0BhOA/ySikJ/tOIODcIZp0yQ U0Mw== 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=l9FLh9mVEBSaTdBrhoB6HBxvMpgNJxmNszp2qjQYpFI=; b=cVOry162v9gBJGvJbD0HnlNvkhFQZ/vIzENmGCFJrOIgkTov+hRaBTjNJr6YTaNOnC c4ydqvWDVIPcd3q2zyADeLM0igKVhQjSVBF/teu42iXIGKV6WrEfjielW5wI8gRvEsyu 0YezpaZzOZtQrYwMAcuJLqWDdo6bwaZ6d1LHjlmcZe5imgYFRByk55lVHMQn52WrWE5N ibAntJgen4cr1aTXF6DQJpFhDkBchi5myAqIXwZ3TxPzKf1OfyGB4YQCHhL3Lw6ZH6m8 Nboj7RqEuJkNRo9thrayPf8ye6gnAZotBz2SKZ34qaRWzN7jrniwZg7EA5WUC3k/k/J4 9NBA== X-Gm-Message-State: APjAAAXg24mwDdwtClvyTIjkze949SdH6gn1rt4IIh2stpGxeBF73uRH EpEOzl0dorz1OaEb01gn5wgDLj71fBA= X-Received: by 2002:a63:f658:: with SMTP id u24mr10998584pgj.399.1551957663076; Thu, 07 Mar 2019 03:21:03 -0800 (PST) Received: from localhost ([122.171.71.18]) by smtp.gmail.com with ESMTPSA id m23sm1898470pgd.20.2019.03.07.03.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 03:21:02 -0800 (PST) From: Viresh Kumar To: "4 . 18+" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH 4.18+] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Thu, 7 Mar 2019 16:50:48 +0530 Message-Id: <03b2be9ff971da005978fe5fab6181c6bcbbee1e.1551957547.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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.18+ # 4.18+ Reported-by: Donghee Han Reported-by: Sangkyu Kim Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- This needs to be applied to all kernels past v4.18. --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 23 ++++++++++++----------- include/linux/cpufreq.h | 12 ++---------- 3 files changed, 17 insertions(+), 24 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b0dfd3222013..8f9cef1ccad8 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 d4ed0022b0dd..1d133df9cb99 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -836,7 +836,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); \ } @@ -845,7 +845,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; @@ -856,7 +856,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); @@ -870,7 +870,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; @@ -896,7 +896,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; @@ -917,7 +917,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; @@ -939,7 +939,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; @@ -986,7 +986,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; @@ -1016,7 +1016,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; @@ -1048,12 +1048,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 882a9b9e34bc..72f59e8321e7 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)