Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp358586pxu; Thu, 3 Dec 2020 02:01:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+dvMnyT7ZpCGMVmuzCCtVro1Z2tgZcbCrEq7r/wliPvglj9SRbb4Ne4DJqWsijYtoQcof X-Received: by 2002:a05:6402:19b4:: with SMTP id o20mr2078488edz.103.1606989698604; Thu, 03 Dec 2020 02:01:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606989698; cv=none; d=google.com; s=arc-20160816; b=Oym9Qt8aFYlDfffugGl8rIGi3sLCyJPcbNg2zJ/12ES0s8rrb3Twp+Ol6TaF+1g2nS Wil3ZdXn0OEM4KTGUhsbpE8rGY3ebU70q90RC1SXN4nbVfsxqTrgqGJv3/T1BX9I034N NBmGIlHDqeJ9Fa0QnWvkWjK4qeJyRCNyR5bNssMTeFvYGTm71ctv2PEZph4jGzelM/ar x0c18B9G3yLaDOjnApg3UcKM7XFhT63P0LgtcAgFs4E0XndgnJzZenWXmJi6b0VldwE7 TUPToKQ1kS2zvQlPF6tGGjm6dwXSkzJZhWLw3Tz3TgWzUB1jToYhWCWynwZdjTeKTFXk RXMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=YuQxAVd/o37PBRyrm10JQKFb5qC7NBswTcj0vcaY41Q=; b=L/H7cPmiKMPZxeqmcA7dt1tDc1/xHtRmLGrXYIRIIzIyC186t9uFkNCNZo5EQa3IG5 n9cYrntu0LQIckFghd9hMuBIe5I/XKr1jsKlBuWosEoZ84sICDtRgv+/n2qrJJbEwOdv pzkr2AuTQZ4TWsb6DDddgwLQB+JAq0dt9k5Mg6QURjLy0ryUISJKruj05drtD3gVlspF 1SmoEYn7xYgb86Gyg1hlF2J6LWJiuP0z4J5UxyqteZHZEvWfkc9PbOO0zuABsxpdO4sj T/dX3rE6wwJI+YQwka10CRsxeqcUfbf3HLC3hmxc5MflXVon/6wlh+N81SrLLpsd1Oc0 ZlsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id en21si762526ejc.393.2020.12.03.02.01.14; Thu, 03 Dec 2020 02:01:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730152AbgLCJ5q (ORCPT + 99 others); Thu, 3 Dec 2020 04:57:46 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:56730 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730121AbgLCJ5q (ORCPT ); Thu, 3 Dec 2020 04:57:46 -0500 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B39tR0N005837; Thu, 3 Dec 2020 04:56:53 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 355vj5n7uf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2020 04:56:53 -0500 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 0B39uoYu008262 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Thu, 3 Dec 2020 04:56:50 -0500 Received: from SCSQCASHYB7.ad.analog.com (10.77.17.133) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Thu, 3 Dec 2020 01:56:48 -0800 Received: from SCSQMBX11.ad.analog.com (10.77.17.10) by SCSQCASHYB7.ad.analog.com (10.77.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Thu, 3 Dec 2020 01:56:48 -0800 Received: from zeus.spd.analog.com (10.66.68.11) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Thu, 3 Dec 2020 01:56:48 -0800 Received: from saturn.ad.analog.com ([10.48.65.108]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0B39ukah003105; Thu, 3 Dec 2020 04:56:47 -0500 From: Alexandru Ardelean To: , CC: , , Alexandru Ardelean Subject: [PATCH v2] iio: core: split __iio_device_attr_init() to init only the attr object Date: Thu, 3 Dec 2020 11:56:42 +0200 Message-ID: <20201203095642.74622-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-12-03_06:2020-12-03,2020-12-03 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012030059 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The __iio_device_attr_init() function initializes a device_attribute object, but mostly it just does a lot of name creation logic. We will want to re-use this logic for name-creation, so this change re-purposes the __iio_device_attr_init() to be a __iio_attr_init() function which just handles the creation of the attribute name. Signed-off-by: Alexandru Ardelean --- Changelog v1 -> v2: * https://lore.kernel.org/linux-iio/20201117162340.43924-6-alexandru.ardelean@analog.com/ * split away from series; I don't know when I will have time to re-visit the entire original series, so might as well move forward a few patches drivers/iio/industrialio-core.c | 43 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 1da7e518435a..5bfcee277879 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -935,22 +935,15 @@ static ssize_t iio_write_channel_info(struct device *dev, } static -int __iio_device_attr_init(struct device_attribute *dev_attr, - const char *postfix, - struct iio_chan_spec const *chan, - ssize_t (*readfunc)(struct device *dev, - struct device_attribute *attr, - char *buf), - ssize_t (*writefunc)(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len), - enum iio_shared_by shared_by) +int iio_attr_init(struct attribute *attr, + const char *postfix, + struct iio_chan_spec const *chan, + enum iio_shared_by shared_by) { int ret = 0; char *name = NULL; char *full_postfix; - sysfs_attr_init(&dev_attr->attr); + sysfs_attr_init(attr); /* Build up postfix of __postfix */ if (chan->modified && (shared_by == IIO_SEPARATE)) { @@ -1046,17 +1039,7 @@ int __iio_device_attr_init(struct device_attribute *dev_attr, ret = -ENOMEM; goto error_free_full_postfix; } - dev_attr->attr.name = name; - - if (readfunc) { - dev_attr->attr.mode |= S_IRUGO; - dev_attr->show = readfunc; - } - - if (writefunc) { - dev_attr->attr.mode |= S_IWUSR; - dev_attr->store = writefunc; - } + attr->name = name; error_free_full_postfix: kfree(full_postfix); @@ -1089,9 +1072,7 @@ int __iio_add_chan_devattr(const char *postfix, iio_attr = kzalloc(sizeof(*iio_attr), GFP_KERNEL); if (iio_attr == NULL) return -ENOMEM; - ret = __iio_device_attr_init(&iio_attr->dev_attr, - postfix, chan, - readfunc, writefunc, shared_by); + ret = iio_attr_init(&iio_attr->dev_attr.attr, postfix, chan, shared_by); if (ret) goto error_iio_dev_attr_free; iio_attr->c = chan; @@ -1107,6 +1088,16 @@ int __iio_add_chan_devattr(const char *postfix, } list_add(&iio_attr->l, attr_list); + if (readfunc) { + iio_attr->dev_attr.attr.mode |= S_IRUGO; + iio_attr->dev_attr.show = readfunc; + } + + if (writefunc) { + iio_attr->dev_attr.attr.mode |= S_IWUSR; + iio_attr->dev_attr.store = writefunc; + } + return 0; error_device_attr_deinit: -- 2.27.0