Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp856472ybl; Wed, 29 Jan 2020 10:50:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzxD3e1pybmBON6PmLvpHEqpQxmzbYZ1O1lmxFyespnpSDBEGlG7PxsWrjkneEiBeG2B8YO X-Received: by 2002:a9d:7f8d:: with SMTP id t13mr499720otp.175.1580323828518; Wed, 29 Jan 2020 10:50:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580323828; cv=none; d=google.com; s=arc-20160816; b=MEgjFADFiViC8nhWkNSr1yXZaHNCIZBX7lUM6TWyV4q9qwr1kPgAXY73ylJ6PzhPjX LeVFFSe+sx+B/EOGloG7fQKbm9jQPtP8BJSrsNVsjCqUmpkjf6s/RKdCiZiWfw6ArNt8 rPhRgnjyOlILYjIA3JywjpUG54qwoW3vsX4u40ELNLaFyFmOCRMN5L5WkanfSbu9ZcPH jJpu7nNKsXOxCwOAHoHgWTH9nNqQ+2mkpvQEc8HCrIm0VpXN7GXQiS/jZ/hapwgvcI7v lF1eWGDhmi7ua1IH8AS5bpAyxN96aQelagls5yJCmz+PWRXn3qZN1pWNYxW6iWtMMg9p FcKQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ovz5VlcbNl/q09jsSoW99zxbUtVg+zxHtLBhHcbw43A=; b=aGhifNPG7DdCnk7ROWGyn2gzljnDq6N+D//L6UZ0tSe9iek6L4kGF9CFeXXjHiIkof rQFjuIsR0EC0yAn9NK/CQOLYDFjySRt3itlqEOgYGSQz9taYEjubAUWDoG803yrR5q0N v6GTL1iUPmuvcTdglAPX9dlUl8xjJ7Y6Lw/NIRbRzOwS8qwacXigpW8kAg+KM5PayF3m zAGyjzaPcJcTBWPWOPIweZz1QrA3b7+Wyphd3FuLjpa0R8EP+Doqq+GBJAWnRTeHbQI6 K5LkpDrSCuBkNqyK+krDPQbqyCwtLydlF4AB3rmVPFgjW03r9Owk7ieZ1z0Cc2I6pXln 6sUw== ARC-Authentication-Results: i=1; mx.google.com; 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 d20si1680560otq.157.2020.01.29.10.50.15; Wed, 29 Jan 2020 10:50:28 -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; 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 S1727364AbgA2SPT (ORCPT + 99 others); Wed, 29 Jan 2020 13:15:19 -0500 Received: from www381.your-server.de ([78.46.137.84]:48004 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbgA2SPT (ORCPT ); Wed, 29 Jan 2020 13:15:19 -0500 Received: from sslproxy06.your-server.de ([78.46.172.3]) by www381.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1iwrrs-0008Vd-UB; Wed, 29 Jan 2020 19:15:13 +0100 Received: from [93.104.127.234] (helo=[192.168.178.20]) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iwrrs-000OrG-Kw; Wed, 29 Jan 2020 19:15:12 +0100 Subject: Re: [PATCH V3] iio: adc: ad7124: Add direct reg access To: Mircea Caprioru , jic23@kernel.org Cc: Michael.Hennerich@analog.com, alexandru.ardelean@analog.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org References: <20200129085356.28899-1-mircea.caprioru@analog.com> From: Lars-Peter Clausen Message-ID: Date: Wed, 29 Jan 2020 19:15:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200129085356.28899-1-mircea.caprioru@analog.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.101.4/25710/Wed Jan 29 12:38:38 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [...] > > +static int ad7124_reg_access(struct iio_dev *indio_dev, > + unsigned int reg, > + unsigned int writeval, > + unsigned int *readval) > +{ > + struct ad7124_state *st = iio_priv(indio_dev); > + int ret; > + > + if (reg >= AD7124_REG_NO) How about ARRAY_SIZE(ad7124_reg_size)? That will make sure that the check is always correct and does not depend on an extra constant that might go out-of-sync with the array. It also makes it easier for reviewers to check that the code is correct. Otherwise they'll have to count how many entries there are in ad7124_reg_size. > + return -EINVAL; > + > + if (readval) > + ret = ad_sd_read_reg(&st->sd, reg, ad7124_reg_size[reg], > + readval); > + else > + ret = ad_sd_write_reg(&st->sd, reg, ad7124_reg_size[reg], > + writeval); > + > + return ret; > +} > + > static IIO_CONST_ATTR(in_voltage_scale_available, > "0.000001164 0.000002328 0.000004656 0.000009313 0.000018626 0.000037252 0.000074505 0.000149011 0.000298023"); > > @@ -375,6 +406,7 @@ static const struct attribute_group ad7124_attrs_group = { > static const struct iio_info ad7124_info = { > .read_raw = ad7124_read_raw, > .write_raw = ad7124_write_raw, > + .debugfs_reg_access = &ad7124_reg_access, > .validate_trigger = ad_sd_validate_trigger, > .attrs = &ad7124_attrs_group, > }; >