Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp789421lqb; Fri, 24 May 2024 13:18:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVl6SYFss2uDLhFB/1NaoLKA99dTG5Mxf2jUm4N9CdR9qUBX0nBtzyiD83Rbspetky+0bY2tC7p/iGIyh2WKeWxT4m7IQG44+Pa0cr9JA== X-Google-Smtp-Source: AGHT+IERR1pgfNke6gir6A3dUHn1/Cwn9hikLwzur7MNKiFj/136VQqIki0zgO85iavg3CDmepji X-Received: by 2002:a05:6512:1152:b0:51b:9254:91e2 with SMTP id 2adb3069b0e04-529661f2cf1mr2381691e87.55.1716581930610; Fri, 24 May 2024 13:18:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716581930; cv=pass; d=google.com; s=arc-20160816; b=KYWJqIncXfArLzim7kZtosgjAFJQteHru25dViCXBfweECLgagZRk+wJPhxi8vrdUX XwfiuZavNo0h2VToCRCqix9giDPE9lICZGPWBZOlSC0pQZvoIuHHfr5U/+Rfmsycs3zL 0ST1Q7Xj5K/Hl3wHnKfIpykXQ7cI4Zy/czs9kOieGF7IXNbYNdz1HJW0jliQG3PvMFnw YbLkcl5MfEwkenE2+hNh8o9jg6mB8tS0cWYJxjrSan5yZnlDsRV2L+yPnqwDuIF2XZcb CuqRXZXWByIn6gUKQ1YcJHDAsIlgZ7QQWaE4vGAtBC5393vtKaGYLEk+X1kRON/AglrV c5LA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pupJ0zX8Gz4rIa61ZbX42+dQviT6t2wR9g3cWXQmpmY=; fh=7hPmKR5OKxIDvuRuRNPbKbRUtyuhJhesp6S32BIB65Y=; b=lqg6qy5mNfpTWigR+cynSj/Ed7ohBRK1i/Mq1o+TFBTR0R2fbhrXkwt+ONlqr7TQ8E C6GJgYaOOD7k/uU27ODzX/8ah1a478xBg/kF5Rom56re6GDMCA+SOqF9c7sCRJbnSTmb NxdSt39zf5MV5mIRZgJGdhDHH5bjUHwGvGgCl1v7IQZXidlvhXsfe1zZRAaA7nVHn48w 0s20Ud67gJcy9E6wsq8SUNJaI5sXVRaZv5OWVJEeCYiHiARMUYohIur0PtmXyhplL1G7 iaUo237qMyac35M506kK+dz9cFaRtC9LEcJ6i8MtuKAacMO0gtQrgLJ1csDU+Z3b/8uK E17w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=vV1Xlu3p; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-189081-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189081-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57861cb2dbasi548314a12.52.2024.05.24.13.18.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 13:18:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189081-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=vV1Xlu3p; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-189081-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189081-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2BD7A1F21BE6 for ; Fri, 24 May 2024 20:18:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AF0884DFD; Fri, 24 May 2024 20:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="vV1Xlu3p" Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D18446AC for ; Fri, 24 May 2024 20:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716581903; cv=none; b=FO61A/J7ziULZILVe2kEF0HItFAVVAH95aH+sB9XF391nm9FwVKp7WJZfFFTe8PonGJmHWmOn7gthxUuM3PXm22W3KsJBAnVB6IdoowT5vWKXHW4FgagTwMwsuRVMl4NR1Y73EXIl3WCzpHHXF/VdQ3tY4Ez2MNe1kLMw0UjJSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716581903; c=relaxed/simple; bh=eU0+2iBlqKN5TWgM1ZRRGbn4eWxUd48oagKUQKm0a2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t1tbOsJKRLsN9F5cppXvVThEA/MX3m+iDRp6UTg/348kPZHoZILCydKbjjOEQOuG5+Zt/onew2AwURuPg6G5XUvcs2p04prHoVAf5JHgJFq513PRBEElxbYeiYRMu5RbmFr6sOUgSUf2VqwpBNh9aBOLu0qYRVViWHgf/XFK3DA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=vV1Xlu3p; arc=none smtp.client-ip=209.85.161.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5b970e90ab8so660688eaf.3 for ; Fri, 24 May 2024 13:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716581899; x=1717186699; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pupJ0zX8Gz4rIa61ZbX42+dQviT6t2wR9g3cWXQmpmY=; b=vV1Xlu3plTJ7qyvbis7eF6SGYrHyEI/C4crImH5d1nhQ84EoOOpHuaOivkTxjDxH74 gOQRQZ+Jkea3Uhp3tINEZ5JzTrkcGW8yppjhjnA11XW/hwx5qcf15KMQsRjtEOX6quIU y6fRPyEA5u/FBYPVqtyXnrvr2KG6+TvNrmOoL2JAmNP+vo302btab9NBKCcMHoCLh5jz ox5/ry4hslr/ZolDGdAK0V/3qD/4sWvj7DNb8lxalbRzFcfWMtOq1nhukPV2fLnXdQv4 OuNFMozkbur7gT6hAmx9QX/x6QN6WsRaeZOgpL/i4fVvzVoX4KJGDV2PjRP0h3ZHAE8V H8cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716581899; x=1717186699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pupJ0zX8Gz4rIa61ZbX42+dQviT6t2wR9g3cWXQmpmY=; b=fHmdmTzmj3U0M0qNXH9DiRJ37O9ssPw0KCHv5RqyBnz8XWRDnUN+AyA92aXAV4vxiw mwCnuiXDQc10SSaeBm/9R+mTrdlbyHXMCSQGVILhAQUEUPiwWipRUCW2r3h7rEXhg17X 0JCl3BDE473YXg+f/kp+bCHn5hnWH3d/IKdOCcAWFLUAa6iOxkn3Oz3fRSHy2em9nNv9 WuG7n3gxINsUJQuceAnVhOAc5duyPoGxr81bIDgAP2mcx+ABrkuuRnOReQ2dJ1ydRjb6 pec0hCRokeLVa8gZLT7tZ2DRjVo4m6uSbOV4VOaKae6V89DpMdg3hBPjAZzK8qoqattv oYvQ== X-Forwarded-Encrypted: i=1; AJvYcCXO6LXdgKE3Gi9or96PqoLLKcoxf6x6Tz2BdOx/cASZzTFxIIi9WcbHmwNsoOK6wtvxkJNbPJ/zKy/x53wewbk+YbTBMPeDFsMCvd7U X-Gm-Message-State: AOJu0YxBee97eOFjgzoxpiCxi4G4UPosS9Fe0TU8A7JSlGEpq1tfKIJq BY8CYtL741sLHf/It0q760NPD77N4/6cKHMQ8bXbqNgMYYh6oNign8lp2eDH+3Qw3B8ElhDEIk3 R8P8= X-Received: by 2002:a05:6871:5810:b0:24e:6d33:9e26 with SMTP id 586e51a60fabf-24e6d33a0eemr1842132fac.15.1716581899115; Fri, 24 May 2024 13:18:19 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-24ca2840481sm516737fac.57.2024.05.24.13.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 13:18:18 -0700 (PDT) From: David Lechner To: Jonathan Cameron Cc: David Lechner , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Julien Stephan , Esteban Blanc , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] iio: buffer: use struct iio_scan_type to simplify code Date: Fri, 24 May 2024 15:18:08 -0500 Message-ID: <20240524-iio-add-support-for-multiple-scan-types-v2-2-a6c328fdfab7@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240524-iio-add-support-for-multiple-scan-types-v2-0-a6c328fdfab7@baylibre.com> References: <20240524-iio-add-support-for-multiple-scan-types-v2-0-a6c328fdfab7@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: 8bit By using struct iio_scan_type, we can simplify the code by removing lots of duplicate pointer dereferences. This make the code a bit easier to read. This also prepares for a future where channels may have more than one scan_type. Signed-off-by: David Lechner --- v2 changes: * fixed spelling of dereferences in commit message --- drivers/iio/industrialio-buffer.c | 48 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index cec58a604d73..08103a9e77f7 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -366,7 +366,8 @@ static ssize_t iio_show_fixed_type(struct device *dev, char *buf) { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - u8 type = this_attr->c->scan_type.endianness; + const struct iio_scan_type *scan_type = &this_attr->c->scan_type; + u8 type = scan_type->endianness; if (type == IIO_CPU) { #ifdef __LITTLE_ENDIAN @@ -375,21 +376,21 @@ static ssize_t iio_show_fixed_type(struct device *dev, type = IIO_BE; #endif } - if (this_attr->c->scan_type.repeat > 1) + if (scan_type->repeat > 1) return sysfs_emit(buf, "%s:%c%d/%dX%d>>%u\n", iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.repeat, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->repeat, + scan_type->shift); else return sysfs_emit(buf, "%s:%c%d/%d>>%u\n", iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->shift); } static ssize_t iio_scan_el_show(struct device *dev, @@ -694,12 +695,16 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev, unsigned int scan_index) { const struct iio_chan_spec *ch; + const struct iio_scan_type *scan_type; unsigned int bytes; ch = iio_find_channel_from_si(indio_dev, scan_index); - bytes = ch->scan_type.storagebits / 8; - if (ch->scan_type.repeat > 1) - bytes *= ch->scan_type.repeat; + scan_type = &ch->scan_type; + bytes = scan_type->storagebits / 8; + + if (scan_type->repeat > 1) + bytes *= scan_type->repeat; + return bytes; } @@ -1616,18 +1621,21 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, if (channels) { /* new magic */ for (i = 0; i < indio_dev->num_channels; i++) { + const struct iio_scan_type *scan_type; + if (channels[i].scan_index < 0) continue; + scan_type = &channels[i].scan_type; + /* Verify that sample bits fit into storage */ - if (channels[i].scan_type.storagebits < - channels[i].scan_type.realbits + - channels[i].scan_type.shift) { + if (scan_type->storagebits < + scan_type->realbits + scan_type->shift) { dev_err(&indio_dev->dev, "Channel %d storagebits (%d) < shifted realbits (%d + %d)\n", - i, channels[i].scan_type.storagebits, - channels[i].scan_type.realbits, - channels[i].scan_type.shift); + i, scan_type->storagebits, + scan_type->realbits, + scan_type->shift); ret = -EINVAL; goto error_cleanup_dynamic; } -- 2.45.1