From patchwork Thu Mar 7 11:22:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 159843 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7313042jad; Thu, 7 Mar 2019 03:23:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzOuyhkfewI/cHRdQpyVgs97exK2fErnIfdJllSQoV4ONP35+n70Y6RsUREoctgpZUW3gA1 X-Received: by 2002:a17:902:846:: with SMTP id 64mr12186955plk.266.1551957781513; Thu, 07 Mar 2019 03:23:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551957781; cv=none; d=google.com; s=arc-20160816; b=gDrRrNTexlLC7QFesJXbPO/rtreMNWF3o+rt4raPDIehze86BH5e9//f3WAPvIGB9u HXdZZU8OVNF4m/DOn4rj9KWJ2xDtuQBDZgsC5eYskRR09Cvf39ZLUCBdSTsznmjErylE q0I3qTFAlRziOb1UG9IBjFu2aZNjxrxzOqxuZh1ktTQ0LyoY0Y29C/cAHgSA359R8csB QwI3gCfzKGv9Z8vodVnGVXJQaxzX27nH8LXHYOj86r5fDOGvrCgTiUXnIWLsVLPbD7fm fFdjP/e5hRLsl+9B4/QKF+Rh07zDKV8M5/ft3C4auRXXVaVIkUq6PdEbUd6U5ZTBp9FG EVYA== 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=0U+m0pyJF5VaQ/beWmZItgbjFOvb0uZjBfWf9EQc/UU=; b=TmjVaPXLhvRwLjVt3zALNvdY6gSHnkXhQqIwWoN3VKJCsnzZdhpMs8HGyaR++jVGKs 4+XRn3YBNOT0PpOwZhNoKQGtCJthLbiNzBy0IyM11OpKBaQ92WC1nWKBswv3RA158+bG c4MSwEsZRTTU6XoYDyytJuVlQjLacYcVxh7pp3xY4tVUGsSY2hOJdzOCaA99YDyyfKG/ xXUaidfNTuwfJgXrGkqADQqSayi57eg01CQV2dzIJH6W2wexsNcpl0klPkjJmmkV90GH YrjzwyU7cMkzlpbTDSX2Rkt6BVD0tMAyVQDPKPiUpagyFQ+6C9GSqhEnzCl0Y1ZaeDP0 7T7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uoVUhvWY; 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.23.01; Thu, 07 Mar 2019 03:23:01 -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=uoVUhvWY; 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 S1726156AbfCGLXA (ORCPT + 11 others); Thu, 7 Mar 2019 06:23:00 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34132 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfCGLXA (ORCPT ); Thu, 7 Mar 2019 06:23:00 -0500 Received: by mail-pg1-f196.google.com with SMTP id i130so11016575pgd.1 for ; Thu, 07 Mar 2019 03:22:59 -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=0U+m0pyJF5VaQ/beWmZItgbjFOvb0uZjBfWf9EQc/UU=; b=uoVUhvWYE69QUn/hN5K3g9x5ar49pIzgHilGFHivOjDFwQnD0cv1OZMyxgdRv+nBzm 4fmmGkHGmSF7c2T8qHLKytrGBKWIybWHZsUApyXpYOxZAEeGAbZQKmDgdLAauBpLX98p XKo74f3GBuVC1TO4IaG+Q1GI94SZMdWR5JvFAUBxIx5pm3nScJHVP26v70CrbO2xfYlP F6y4Z9x9OGUVRMRqwHhsor/HhS03f/HsEyAtLfOC2cjVM7nGusCZfeZeyNI8owZT00ZL 20Jvq0yEKTKzLQHD7IJo/vS6sH9aba7DiE0GOUjGyzXTtusMsozhO+nGt2ueJGmunjf5 6DjQ== 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=0U+m0pyJF5VaQ/beWmZItgbjFOvb0uZjBfWf9EQc/UU=; b=rMH1ed7r3QRYXfCn30xFhS0ELiUAwpeHzW+IcKdhoW4NTowa21VwENflwRBGsTVs66 /X1b6fPByx02GGFtt/DfKoQ5vuJPT5ZFX1AZXKhrAW5rtea92O+shAORIurZFy40lgGD 6THTnkcfpdhtVRvv16hxaiUadhiR8My1h+opm9fjRLLDfymer2wk8DKiIz4Lbj3b6loS 96O+oqC1ZRWjlc/i1M83b5LNLC2UCpB0qFj+hZI1GLqd3Oo0pyFMx63TIGDttvQOykhK 1JHHCWhpxZGh6tCFJS6vKgWiUbJNdXbNxUljc/TU7CQQ7ig5LhyemldfatRfLYM0vfKy 7d8Q== X-Gm-Message-State: APjAAAVP0cnvGoCKneQgk0pA8QsnbapXDNmamZtl1iohxY0vO4xmTCmZ V7KDg5HhStXrZcquLNy1lKVSJg== X-Received: by 2002:a63:1053:: with SMTP id 19mr10977754pgq.55.1551957779416; Thu, 07 Mar 2019 03:22:59 -0800 (PST) Received: from localhost ([122.171.71.18]) by smtp.gmail.com with ESMTPSA id l7sm13942781pfj.162.2019.03.07.03.22.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 03:22:58 -0800 (PST) From: Viresh Kumar To: "4 . 6+" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH 4/6+] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Thu, 7 Mar 2019 16:52:52 +0530 Message-Id: <81e2be4499ef1a3c315c4c406f25ea12ea197ae5.1551957754.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.6+ # 4.6+ 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.6 to v4.9 (including both). --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 14 +++++++------- include/linux/cpufreq.h | 12 ++---------- 3 files changed, 12 insertions(+), 20 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b Reported-by: Donghee Han Reported-by: Sangkyu Kim Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index c4acfc5273b3..057c44cb0c67 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -434,13 +434,13 @@ EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end); * 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 b230ebaae66c..0936301637fa 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -521,13 +521,13 @@ static void __init intel_pstate_debug_expose_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", limits->object); \ } 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; @@ -543,7 +543,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; @@ -554,7 +554,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; @@ -567,7 +567,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; @@ -591,7 +591,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; @@ -616,7 +616,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 718e8725de8a..bfd93dbe8af2 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -198,20 +198,12 @@ __ATTR(_name, _perm, show_##_name, NULL) static struct freq_attr _name = \ __ATTR(_name, 0644, show_##_name, 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)