From patchwork Thu Mar 7 11:22:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 159842 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7312581jad; Thu, 7 Mar 2019 03:22:28 -0800 (PST) X-Google-Smtp-Source: APXvYqweTX67b5QATAdfQ3aYSNQf2FJW6zq3j7X+byyNx+g8shRJZgYblf25okzHD0WmgGq65xhB X-Received: by 2002:a62:b40b:: with SMTP id h11mr12225126pfn.108.1551957748240; Thu, 07 Mar 2019 03:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551957748; cv=none; d=google.com; s=arc-20160816; b=finFBtpuAyGPn7qenCU1zVqi1qKakPgebKNl4rQh9QAreILTbWp5jA2c6RUx1kRzl3 9Uj343jan2z0yTZSIfybMo61nmTUewjWxizG5zu3uF6in7OHpzkSM0iGR4Wq/s/wGH0B coBpXNy//x35s/DCHwSvXhTL147dH75JKTFsWfBKDX49gdnxvM7hkttgTJu2BiBcIjhB 26nv+oDdYIjElF41oq8EVvr0AxZTRPsdpiItwbevUW7piN8xRpriCiloJMVPq5jEGPVO sJnruuZfG8SOi59gGpd44jZp8L4WlCnLw+/CTUfwsMf9TetnzPrlKlHAVIOpaHNL4Vno CZhg== 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=WgaJsqqDn5qGN+nnBthqV3CWyfaqgqm8gt+MWCjGUD4=; b=CTXaefXiR+21b1PBcgmXCMLArOk42kQNS7jYG3ABmaF29FTqyuqN39hykna0lg8xxE xZKD/e0jS2fk3KBBqXnvE73w8bQLyfliVOnrHdCKrYkMtKzvCn/67pNhKo5+S5euIssb U59Dapqb6mQ8OuZCzXEwhjeiHHOM1I3MJwQCLYgnS9GCJ1NlIaYgA6bFSXwmm1ym3ucU wLduhNzQ9nY2NJ85ddM7h+PwuhC4se0Ve0z8VO1s+ue+2iufqlP5td/gsDsRWhq0uLUW hOvegIdLvrbW2+SIMSI6hk8Hj2YTC44Qq0hS4D3Iqf7XmiYGkDFS+rslzFUlNdaPesci jhiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e4vSpudC; 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.22.27; Thu, 07 Mar 2019 03:22:28 -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=e4vSpudC; 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 S1726143AbfCGLW1 (ORCPT + 11 others); Thu, 7 Mar 2019 06:22:27 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40626 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfCGLW1 (ORCPT ); Thu, 7 Mar 2019 06:22:27 -0500 Received: by mail-pg1-f196.google.com with SMTP id u9so11007209pgo.7 for ; Thu, 07 Mar 2019 03:22:26 -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=WgaJsqqDn5qGN+nnBthqV3CWyfaqgqm8gt+MWCjGUD4=; b=e4vSpudC/QyDkjUT9RKlg31K+WD2e1PQW3IpWArhvorjVztfb+/fGAwzEEDDsecuxC 5GHTB0R7RRAUeuZmkxNnaniVWrLtZTfuoeX+uYgzInRo3G1a86MBkXoxjkC8su0hFGRz doG0tjib1X/L7Fp3QZypheywtGPoplgypOHbnjZ/craPjmInZumHtHWVAV+qvLhQ9kn3 YXPwjZnGEUgtMNmHL+qn8w5DVyEqjlCNitGCU7jZkh43xKK2FbbF2JzjxAbWuEzP6sEg /d33famauLaEoPrll8UdKng0yLdroXobfaDxoY8O2KDTnzzvPGa8SP1nvRAAQdF5+7S5 u0fg== 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=WgaJsqqDn5qGN+nnBthqV3CWyfaqgqm8gt+MWCjGUD4=; b=HNexE+2o2Dde4Bz7TUAi5h1sZLVZTN40ABFNzV22lNerYkplA+64IY7GpR3501sgDd QiYCQQNPO2aeFzpf9Xh413F5Hv4HMiV0UwsL35ZGCyqjkpfqrYhwl7dQb64K4EivjtlJ wqjcJZWmCzFXF7aVpVx0mYDEQyJcnrIkQmKTnoS5TOmj0S7KItLSu5NT3ulXOHRbf5Wl DCVLI6Z9j6k4XtjBKaU1WDUVwOiK2GRxS/tGTREU7WtmllrgEK4AqIA1CBDtEyPIhIdv AbnKaYBqn+ypuF0mwqiPa5Yx7BGnatCiIUEr8fvk3sQqNaEmGj+P1B5T6dtck6Z1lCJU OqJQ== X-Gm-Message-State: APjAAAWQ4h5U5OjJtTpsusknZ6flCC4ZORa+v4/hMiN1JfBLOaiBxkRr M4BzbZAA7krUNjnAQRKAHhD1cw== X-Received: by 2002:a17:902:248:: with SMTP id 66mr8057508plc.286.1551957745962; Thu, 07 Mar 2019 03:22:25 -0800 (PST) Received: from localhost ([122.171.71.18]) by smtp.gmail.com with ESMTPSA id f65sm7726952pff.21.2019.03.07.03.22.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 03:22:25 -0800 (PST) From: Viresh Kumar To: "4 . 10" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH v4.10] cpufreq: Use struct kobj_attribute instead of struct global_attr Date: Thu, 7 Mar 2019 16:52:20 +0530 Message-Id: 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.10 # 4.10 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 v4.10 only. --- 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 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index cc475eff90b3..984ad3857622 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 50bd6d987fc3..8685a4caab2c 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1043,13 +1043,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; @@ -1065,7 +1065,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; @@ -1076,7 +1076,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; @@ -1089,7 +1089,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; @@ -1117,7 +1117,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; @@ -1145,7 +1145,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 7e05c5e4e45c..21eb84c2ad1c 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)