Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5903432imb; Fri, 8 Mar 2019 05:08:38 -0800 (PST) X-Google-Smtp-Source: APXvYqzJPsuX9ttoBIi5MzbRNPHXlVo8zx5h2zyH/RAXyYu2Em/nUf/jbE0BgRJU05NWmuxX+x1e X-Received: by 2002:a17:902:5ac9:: with SMTP id g9mr18876055plm.205.1552050518330; Fri, 08 Mar 2019 05:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552050518; cv=none; d=google.com; s=arc-20160816; b=xSY99Q19f0baVOtsEGuG0KAn/UepQIChpOqsdOaayums/Ed7o+1Yg+oV9ubuipfA78 d6U+/GZ6Eb0mG3UdGb5ZavidoWHmlQG6TExRqKKkliLg0X3NU9R+sfYSwTTKJNRGKVfA SRuC9XhgrfQy97ewT6PQN0017VBGq5Fk+hjZJRBLF5E2QREkknIQLDgOxsP4pD7fbZmM Ctdq8kESzfDJBO2aSt35ehiCs3oR3NW7D0Hl8k4xwKZ5fFpwj0AYJq0I2qJSXwd8bibx UzNwceltMXmQX83wjpctgIyFSZ3g2oaKBFF9I9zkzGXO3+n5D7M8AipRf6YMGmxd0XKx xuwA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fMWyANxygrNSceaM0u61UM/jwEWrtCfNStqENYd9Gck=; b=xFyaO0ATbyegaFDXtmAGAUps9wYi/xJ9n43mSi0WwpMo4YymzPdSDDFjZCOl5cNoSL 1YIf7HRE88NOVPQX/5pjbbKkZmDcgCMEZD8ANA2NOxQlgKgAgh0fPWFMPE9EFGTyneK2 EZKyOOhmeJFI3uS7LBfHucfPohPuMZbCYLCFcWltBhco+C/5wogoWk5mkcUDKrbaVLKw kC5AZKHHmL26ZodPDX+Md/N2goMhMyJ6WTN61WCMW1cYBsZS6oSsObQctRRiVuvSktqM ho3rflZ+M6ons1uux9g2LzGJpwT5+vu78YMk3H7QEnxpm8DtoD1eCMLiPDtPEgcSVaWv LX/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="G/qg0dL5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t15si6296746pgv.503.2019.03.08.05.08.22; Fri, 08 Mar 2019 05:08:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b="G/qg0dL5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbfCHMxe (ORCPT + 99 others); Fri, 8 Mar 2019 07:53:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:57210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727149AbfCHMxc (ORCPT ); Fri, 8 Mar 2019 07:53:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 25C772085A; Fri, 8 Mar 2019 12:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552049610; bh=8BIM5txYh0hQpTGXMdpLDc/FJYhbwLA9xy1Gb91XfFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G/qg0dL5PF78oyxebx2FByQ5G6j8sAK3T6mudt+y25bMOPWVyzfGwN0pnt8BXaTXd e97R+O2Zb7ijQ6WaPzWtQ+NOU8gP1kstaxNGsSH9YC8iB2+GoaBZmCsB1s/U6F7d0a U0iSkSm2Eqb0IWvgQR9clGR/6AsvCE2X7BzOMAjo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Donghee Han , Sangkyu Kim , Viresh Kumar , "Rafael J. Wysocki" Subject: [PATCH 4.20 01/76] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Fri, 8 Mar 2019 13:49:13 +0100 Message-Id: <20190308124914.844414523@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308124914.789210760@linuxfoundation.org> References: <20190308124914.789210760@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Viresh Kumar 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. Reported-by: Donghee Han Reported-by: Sangkyu Kim Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 23 ++++++++++++----------- include/linux/cpufreq.h | 12 ++---------- 3 files changed, 17 insertions(+), 24 deletions(-) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -545,13 +545,13 @@ EXPORT_SYMBOL_GPL(cpufreq_policy_transit * 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; --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -873,7 +873,7 @@ static void intel_pstate_update_policies /************************** 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); \ } @@ -882,7 +882,7 @@ static ssize_t intel_pstate_show_status( 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; @@ -893,7 +893,7 @@ static ssize_t show_status(struct kobjec 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); @@ -907,7 +907,7 @@ static ssize_t store_status(struct kobje } 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; @@ -933,7 +933,7 @@ static ssize_t show_turbo_pct(struct kob } 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; @@ -954,7 +954,7 @@ static ssize_t show_num_pstates(struct k } static ssize_t show_no_turbo(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { ssize_t ret; @@ -976,7 +976,7 @@ static ssize_t show_no_turbo(struct 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; @@ -1023,7 +1023,7 @@ static ssize_t store_no_turbo(struct kob 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; @@ -1053,7 +1053,7 @@ static ssize_t store_max_perf_pct(struct 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; @@ -1085,12 +1085,13 @@ static ssize_t store_min_perf_pct(struct } 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; --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -254,20 +254,12 @@ __ATTR(_name, 0644, show_##_name, store_ 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)