Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp726601rdb; Thu, 30 Nov 2023 17:29:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdSnVvey2VtKLcJ7yVVWcs1qIMKNvBiKAWcNUnTmzyVXeOlSL9UOfZCpfbNrpELQExgumh X-Received: by 2002:a05:6a00:4484:b0:6cb:4361:9f75 with SMTP id cu4-20020a056a00448400b006cb43619f75mr23718620pfb.22.1701394181981; Thu, 30 Nov 2023 17:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701394181; cv=none; d=google.com; s=arc-20160816; b=eSVfIw/c9NdOBu/N2QCYhjDYBInamfW8w7GcHU49DJNzzf7zjpdo8xMONc1vfniu6b LZ/n942avggB/T1ocqBk+Aa6M37tgH4ExgUmlQLzvK0UWDFNd3yWHEJUGBd/55+1slfo 9L1cIYy9ptk5YN/jalMg+mLFJbSLtODAFwOtyIY7XJA2WFsFSPYY2bulu1NF0RDxXpWd vromscXiO7xfBXALrRxREMn+rBq4HnRZNHwdzuTs2Sk+ikCX6DXbipOo0I5YhtoqiBi/ Qec+NV05Mgf0zUvSvgc5T0KZRc7lsJ7yZXp3SG93uQknnYLIBt5ZVlYc2bE9zsGPLTyK l1jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+x48F9cup90mh4fl4kQnmF9ElZA62U23cKXVft3X7Gk=; fh=G1j+NqIZIszoTQ3NlEcbRDPGSRYv1Vu0XuFPJrY9Ht4=; b=Xwkz3sF8BGXg+kKooZdyTo62DqGkIgw6WRlZiR0Fcrnt1kYwAyPY13euA2Wv9cxb62 AsRcAr/qgEhsbK58nj6ryAZUXCT3RgLheIVWRtC9tACggt3KRdnQuNMPcmU8tnd/vxxV 1QUJ/d67j0b/JhnNxn4FdgYMSJL5KPYrBuQHttd3nPb5OBL0RgcHIq/V0kMhAnkiBAke EoLtK+qrnOy/hYIlKy8KhuXuhH162GPIF/rL9ZFS6mwe7WsPypu2JfwyI4bNvOrZycPs mtIrkR8u7isJdjtLMdvV0BnOPmW4X30oj5vzFqkVsltONPg0PEd+EdNyF45aMfMHLe4N q37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m427PfKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id 1-20020a631041000000b005bdbcdc9e3dsi2487521pgq.142.2023.11.30.17.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 17:29:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m427PfKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2C6938062917; Thu, 30 Nov 2023 17:29:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbjLAB3W (ORCPT + 99 others); Thu, 30 Nov 2023 20:29:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjLAB3V (ORCPT ); Thu, 30 Nov 2023 20:29:21 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3AF210D1; Thu, 30 Nov 2023 17:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701394167; x=1732930167; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Od0OV/m0R2tQLMJWSylL1P+SOYauHRST34A3DngAhiY=; b=m427PfKTAZEicOESssWYVFDYP441fzXZr12MbapD7EtOzHskZH7hmjDZ rXBbJBusqXKCS8i5//gnlIqXYKkGwVKlbguo8e6pWrFNDTNyFNQUZbTdT 2jY/6kXLcA/fJRXjkc9WuBpu3+mtK5WmmUdhhLTD4laW1jQvlAeeQlI8m 4KCv9I9jUtTPiy26u0UsB/2YHmKfFifCPrD2DheDeZzPM64LYIoqhj3uP Nz++iCCBlHEM5aiV2j0J0r7bJTrVT7TQV5hKZO9C3nRg4gGfR/FtybQMe H/v9gDTIozWly9i7wJmJiITgCm/hMxbTSNGIV+Q1ZIABTaCXosJ5w0gsc g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="303875" X-IronPort-AV: E=Sophos;i="6.04,240,1695711600"; d="scan'208";a="303875" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 17:29:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="745821708" X-IronPort-AV: E=Sophos;i="6.04,240,1695711600"; d="scan'208";a="745821708" Received: from araj-dh-work.jf.intel.com ([10.165.157.158]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 17:29:26 -0800 Date: Thu, 30 Nov 2023 17:27:00 -0800 From: Ashok Raj To: Zhang Rui Cc: linux@roeck-us.net, jdelvare@suse.com, fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Ashok Raj Subject: Re: [PATCH 2/3] hwmon: (coretemp) Remove unnecessary dependency of array index Message-ID: References: <20231127131651.476795-1-rui.zhang@intel.com> <20231127131651.476795-3-rui.zhang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231127131651.476795-3-rui.zhang@intel.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 17:29:39 -0800 (PST) On Mon, Nov 27, 2023 at 09:16:50PM +0800, Zhang Rui wrote: > When sensor_device_attribute pointer is available, use container_of() to > get the temp_data address. > > This removes the unnecessary dependency of cached index in > pdata->core_data[]. > > Signed-off-by: Zhang Rui > --- > drivers/hwmon/coretemp.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c > index 6053ed3761c2..cef43fedbd58 100644 > --- a/drivers/hwmon/coretemp.c > +++ b/drivers/hwmon/coretemp.c > @@ -342,7 +342,7 @@ static ssize_t show_label(struct device *dev, > { > struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); > struct platform_data *pdata = dev_get_drvdata(dev); > - struct temp_data *tdata = pdata->core_data[attr->index]; > + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_LABEL]); > > if (tdata->is_pkg_data) > return sprintf(buf, "Package id %u\n", pdata->pkg_id); > @@ -355,8 +355,7 @@ static ssize_t show_crit_alarm(struct device *dev, > { > u32 eax, edx; > struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); > - struct platform_data *pdata = dev_get_drvdata(dev); > - struct temp_data *tdata = pdata->core_data[attr->index]; > + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_CRIT_ALARM]); > > mutex_lock(&tdata->update_lock); > rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); > @@ -369,8 +368,7 @@ static ssize_t show_tjmax(struct device *dev, > struct device_attribute *devattr, char *buf) > { > struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); > - struct platform_data *pdata = dev_get_drvdata(dev); > - struct temp_data *tdata = pdata->core_data[attr->index]; > + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TJMAX]); > int tjmax; > > mutex_lock(&tdata->update_lock); > @@ -384,8 +382,7 @@ static ssize_t show_ttarget(struct device *dev, > struct device_attribute *devattr, char *buf) > { > struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); > - struct platform_data *pdata = dev_get_drvdata(dev); > - struct temp_data *tdata = pdata->core_data[attr->index]; > + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TTARGET]); > int ttarget; > > mutex_lock(&tdata->update_lock); > @@ -402,8 +399,7 @@ static ssize_t show_temp(struct device *dev, > { > u32 eax, edx; > struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); > - struct platform_data *pdata = dev_get_drvdata(dev); > - struct temp_data *tdata = pdata->core_data[attr->index]; > + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TEMP]); > int tjmax; > > mutex_lock(&tdata->update_lock); > @@ -445,7 +441,6 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev, > tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; > tdata->sd_attrs[i].dev_attr.attr.mode = 0444; > tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; > - tdata->sd_attrs[i].index = attr_no; I was naively thinking if we could nuke that "index". I can see that used in couple macros, but seems like we can lose it? Completely untested.. and uncertain :-) diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h index d896713359cd..4855893f9401 100644 --- a/include/linux/hwmon-sysfs.h +++ b/include/linux/hwmon-sysfs.h @@ -12,36 +12,35 @@ struct sensor_device_attribute{ struct device_attribute dev_attr; - int index; }; #define to_sensor_dev_attr(_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr) -#define SENSOR_ATTR(_name, _mode, _show, _store, _index) \ +#define SENSOR_ATTR(_name, _mode, _show, _store) \ { .dev_attr = __ATTR(_name, _mode, _show, _store), \ - .index = _index } + } -#define SENSOR_ATTR_RO(_name, _func, _index) \ +#define SENSOR_ATTR_RO(_name, _func) \ SENSOR_ATTR(_name, 0444, _func##_show, NULL, _index) -#define SENSOR_ATTR_RW(_name, _func, _index) \ - SENSOR_ATTR(_name, 0644, _func##_show, _func##_store, _index) +#define SENSOR_ATTR_RW(_name, _func) \ + SENSOR_ATTR(_name, 0644, _func##_show, _func##_store) -#define SENSOR_ATTR_WO(_name, _func, _index) \ - SENSOR_ATTR(_name, 0200, NULL, _func##_store, _index) +#define SENSOR_ATTR_WO(_name, _func) \ + SENSOR_ATTR(_name, 0200, NULL, _func##_store) -#define SENSOR_DEVICE_ATTR(_name, _mode, _show, _store, _index) \ +#define SENSOR_DEVICE_ATTR(_name, _mode, _show, _store) \ struct sensor_device_attribute sensor_dev_attr_##_name \ - = SENSOR_ATTR(_name, _mode, _show, _store, _index) + = SENSOR_ATTR(_name, _mode, _show, _store) -#define SENSOR_DEVICE_ATTR_RO(_name, _func, _index) \ - SENSOR_DEVICE_ATTR(_name, 0444, _func##_show, NULL, _index) +#define SENSOR_DEVICE_ATTR_RO(_name, _func) \ + SENSOR_DEVICE_ATTR(_name, 0444, _func##_show, NULL) #define SENSOR_DEVICE_ATTR_RW(_name, _func, _index) \ - SENSOR_DEVICE_ATTR(_name, 0644, _func##_show, _func##_store, _index) + SENSOR_DEVICE_ATTR(_name, 0644, _func##_show, _func##_store) -#define SENSOR_DEVICE_ATTR_WO(_name, _func, _index) \ - SENSOR_DEVICE_ATTR(_name, 0200, NULL, _func##_store, _index) +#define SENSOR_DEVICE_ATTR_WO(_name, _func) \ + SENSOR_DEVICE_ATTR(_name, 0200, NULL, _func##_store) struct sensor_device_attribute_2 { struct device_attribute dev_attr; diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c index 975da8e7f2a9..c3bbf2f7d6eb 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.c +++ b/drivers/gpu/drm/i915/i915_hwmon.c @@ -239,7 +239,7 @@ hwm_power1_max_interval_store(struct device *dev, static SENSOR_DEVICE_ATTR(power1_max_interval, 0664, hwm_power1_max_interval_show, - hwm_power1_max_interval_store, 0); + hwm_power1_max_interval_store); static struct attribute *hwm_attributes[] = { &sensor_dev_attr_power1_max_interval.dev_attr.attr,