From patchwork Thu Mar 7 11:23:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 159844 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7313615jad; Thu, 7 Mar 2019 03:23:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzzT9KbL1tYNyn7fm+TMY/Lxq8nicqL6hMg7G17JOcSS5PGCIQKRjzoEny8AxMoKww6XMg8 X-Received: by 2002:a62:d281:: with SMTP id c123mr12195041pfg.210.1551957819205; Thu, 07 Mar 2019 03:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551957819; cv=none; d=google.com; s=arc-20160816; b=nvR9TiqRm+nk8PvTIFQ1uO2QHaFU1BsE6fFVRS1dGvHhHmJXgjPSAFdKXniJVmIx11 pBiNiOd+y83GwIKJxLtvVmxZNkLh3ChTFg7LiKRlMyoENjU1zxyJ9oXC7DF1K0v+wqI7 /+iicFs+hyqHv+GbcQu1q/Ufi+d9dUeHVFhDL60OV5Coe0UNKIVZgb0SGCr2XA7vZZwQ cUPdt2cHJ4j5wc2JzbNT24/pqa6hTRIe02+sYOB3qNfM7zAwEmUmsH4ifdjgY2Xumuy1 yfXc92+yulhi8cqClSR7XXjh0WiW1GpmY5EMH3PFp1N5XBSh1lmOROiKncdg7yxC5REi S9qQ== 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=AaQodzxA4RmTCvCRIikN5Bw1thjZK7N9tHFEdnK10e8=; b=rYOChH/7dgk1iir5JHwFLOVR2rhgLqSWSPGwdevxorDio4584sc/xNSd+QoWM/UhcG 2X7KMV4kplvaR5+Qi3gZMnEK9H4KXu95hilrw6tdyL3h2KBEvRJg+hRevy0oLxEeDU4M UQnP7EmAqLxezLT/4AeY+cSyslRQ18Tm87hNn0I1+U74v9oY7VEGJW3qVBMIgyHTCsre ufUlKtA+Hvlvtc0PJzktU1Ov2Kl8uOx0DhsBaYQ6NdmAnIq36L6sJ+tI2MeaeOQzBB/R WDREANJuXILviTNLyGyWv15etJAG6V0GjaQKO7yogtKo9ytFAt28zhJf24VFZ2YRPOhd QfJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MHSkZOE4; 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 f67si3693495pgc.182.2019.03.07.03.23.38; Thu, 07 Mar 2019 03:23:39 -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=MHSkZOE4; 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 S1726308AbfCGLXi (ORCPT + 11 others); Thu, 7 Mar 2019 06:23:38 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37693 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726148AbfCGLXi (ORCPT ); Thu, 7 Mar 2019 06:23:38 -0500 Received: by mail-pg1-f193.google.com with SMTP id q206so11018047pgq.4 for ; Thu, 07 Mar 2019 03:23:37 -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=AaQodzxA4RmTCvCRIikN5Bw1thjZK7N9tHFEdnK10e8=; b=MHSkZOE4E2VDh9hlagGed4hdeFOCeDW/a7GmJfIO1eOgtW1mc7d/E8iHA37AjYAQrL w4bvD4TCndCn5P2iOJzC/EC8w2E4icdfIdvpM9pMEiB66SUnuUuFwfdk3KORQH97EASa DvYGe7zTfF1EMBkgDzmakpzeMkWfiHGlJvNY3gW9oZcAMUwRAfK/IfcfKUYDJqKmpX82 uTJATMozq6g+8PnLVdQOTNDF+PTX49/P8xY5vt1YtAa41CH1bCynpqHSlnWJ16jnU3v8 Pe6xoB6Qcd2qTSweJcyJ7gEp9DzWjTmMxN9MsSeW8sw1JsVgYS9Q6e6XRgM7tc1G9hsF 0L/g== 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=AaQodzxA4RmTCvCRIikN5Bw1thjZK7N9tHFEdnK10e8=; b=fGlX7KZ4Z03ef9y8JD5pPYpBGzZhsD4pZGXXZRYNTQ125eW1hClpxKl2ZpZHW4zmxr 6gDAfMgooPVfWEsPFuj3VtoABfrkRlSXXIKsq8iqv1/JXLTPGtSD6faUAglSSUMBXkqS xLL0c4RzTb0TBqwYC7PvYKhC5JFqQjNRZzIQu2ohTa7y3Jor7Hk+hh6I5kZlWtI3JPT3 /VK2S4Ur0USoUj1+/f2Iya1zqJfqjqaVu8W9U8kiat2fkYMIgc2W/tlXarWnbgEAPPhm FPm15uIeFA+SEYEs1M4nnau1rL1VZhwghtc5O6BjNuB7qyOHjxeOBzAbiHGKY8AuieLj uQdA== X-Gm-Message-State: APjAAAUzeRGNfgIkfyQfFOmjcXsBUBtoeVOFB7fm7OIyqJynjUCBPhAM 5Zvk1zoizQUbmg5egM1xQm7wvA== X-Received: by 2002:a63:3541:: with SMTP id c62mr10796583pga.157.1551957817086; Thu, 07 Mar 2019 03:23:37 -0800 (PST) Received: from localhost ([122.171.71.18]) by smtp.gmail.com with ESMTPSA id n24sm14684600pfi.123.2019.03.07.03.23.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 03:23:36 -0800 (PST) From: Viresh Kumar To: "4 . 0+" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH 4.0+] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Thu, 7 Mar 2019 16:53:33 +0530 Message-Id: <4f8ea1c92397b7d88aa8e0fe825b3e14b70ef85c.1551957797.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.0+ # 4.0+ 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.0 to v4.5 (including both). --- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/cpufreq_governor.h | 10 +++++----- drivers/cpufreq/intel_pstate.c | 14 +++++++------- include/linux/cpufreq.h | 12 ++---------- 4 files changed, 17 insertions(+), 25 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 8ae655c364f4..6c33b355c405 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -407,13 +407,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/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h index cc401d147e72..d4fadeb4c246 100644 --- a/drivers/cpufreq/cpufreq_governor.h +++ b/drivers/cpufreq/cpufreq_governor.h @@ -48,11 +48,11 @@ enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE}; /* Create attributes */ #define gov_sys_attr_ro(_name) \ -static struct global_attr _name##_gov_sys = \ +static struct kobj_attribute _name##_gov_sys = \ __ATTR(_name, 0444, show_##_name##_gov_sys, NULL) #define gov_sys_attr_rw(_name) \ -static struct global_attr _name##_gov_sys = \ +static struct kobj_attribute _name##_gov_sys = \ __ATTR(_name, 0644, show_##_name##_gov_sys, store_##_name##_gov_sys) #define gov_pol_attr_ro(_name) \ @@ -74,7 +74,7 @@ __ATTR(_name, 0644, show_##_name##_gov_pol, store_##_name##_gov_pol) /* Create show/store routines */ #define show_one(_gov, file_name) \ static ssize_t show_##file_name##_gov_sys \ -(struct kobject *kobj, struct attribute *attr, char *buf) \ +(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ { \ struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ @@ -90,7 +90,7 @@ static ssize_t show_##file_name##_gov_pol \ #define store_one(_gov, file_name) \ static ssize_t store_##file_name##_gov_sys \ -(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \ +(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) \ { \ struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ return store_##file_name(dbs_data, buf, count); \ @@ -251,7 +251,7 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate) #define declare_show_sampling_rate_min(_gov) \ static ssize_t show_sampling_rate_min_gov_sys \ -(struct kobject *kobj, struct attribute *attr, char *buf) \ +(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ { \ struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \ diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 872c5772c5d3..cc3936a0cdf0 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -337,13 +337,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; @@ -359,7 +359,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; @@ -370,7 +370,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; @@ -383,7 +383,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; @@ -407,7 +407,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; @@ -426,7 +426,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 2ee4888c1f47..5714d643dd4d 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -200,20 +200,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)