Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1368955lqb; Thu, 30 May 2024 08:15:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUsWu7NjZ3MKj0vswVrYVA3ubVIwhnWQdqnRt3KEUytpZ3M+acU2A9Sn+GNzoTknziscc0S11sRkR84CEUmyEgQtKa2UXewwFDxzU90vg== X-Google-Smtp-Source: AGHT+IHMzTGq/segocmgkIlhBp3h5VWi1hUEOfD3J72GlATyRp567S6jv06OsN0Vij1r+0ZxsPon X-Received: by 2002:a17:90a:ccc:b0:2bd:b091:bae1 with SMTP id 98e67ed59e1d1-2c1abbf93fbmr2413965a91.25.1717082130089; Thu, 30 May 2024 08:15:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717082130; cv=pass; d=google.com; s=arc-20160816; b=mmGrmQDcXSlQtv848rM8ynWAlQVLECYZw4QnYCZC9ZLiwrrOvH3mHbsHEYbyy7ZKmL LEd4SBU2ghMShOiySjKLJutZvwyi7tv9UvwJrIuPBdXhWNcB7xZo6uyGUmvoOgQq/wL7 narBCWxJLlYsBmFfaC03GFwprxNru13p+qPRA/Rmo+4ah+8Q0LOa2IuxTkC/9Rmi0i4W qg7na59GHhyIOVvLLZahaP3mKLfk79OoR7Kzqycla2HopCeQ6uBYNcjBFlUstWoyJd3t 2jBk1koQoxCpEKQaqkPaK/zRj5uqPal4WUpFUszyraK4B4fL6nThQ4zA5RdvuzVJnvJC 10Kg== 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=etE6dgY3ZZdPAacneXLnj+Gq8AOjqNZk3KGQXXeWybg=; fh=uFl2iXbnni8Z/efYmjEb38dMukN0Jq5aWAKdySIm6Eo=; b=Ek7R4+dv7mbddOCZb4lO7UYlV17AP8qlKeBpM8XoCqj3p9crX9en3vdUJ92x2I3T8B R155v/AmJJCFoJ6y9emw51UDJd2UB6k+VbX20nLX12r1xF4tqTCFsDEIhJ7i2SmRpYcv yVP7AmfvbmJ3IPl26iNb7+iNFk+vbt8u6Jbi+yeKdzm8s69kLkzwNRLRm2BEow5P3/Z+ YuNAYure9vOIM6wZxf1ZZT4KiVyAA0/6LR8JOGT8Fc+u8zQYDMBfr/2+Jjzruwh3Syzo qpmP+T2Tbf76QQk40P9gle0Y7orU1i7SwUHXFniLAWUutdmbG2PCtw/RYYXOWT530BM9 7cuQ==; 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="gGRQ/DEb"; 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-195586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195586-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a776d872si132676a91.29.2024.05.30.08.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:15:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="gGRQ/DEb"; 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-195586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195586-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id ADB312876BA for ; Thu, 30 May 2024 15:15:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA312182D17; Thu, 30 May 2024 15:14:34 +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="gGRQ/DEb" Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 EA5C318755D for ; Thu, 30 May 2024 15:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717082073; cv=none; b=ilhsSHVr6BmVkpmbrZ2ewhv8EN4tuYBVNzSbtoC7YEa18ujgwPT8RmKrVMBUomXpKs719szVtfXaKSmCNWcyjk8LLbstAHNnQ8TSbUsCtfyVKKxWu03bcYtUwHqexJFuYENwYSgvQbUVH2Gv7Bctvwz+b67CNTpoztddUs2uCLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717082073; c=relaxed/simple; bh=DY1EeagIOvwFMlI+7rFTIpnLVX0E678JEXnN9mdCJIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P22lEF1Fdn/qzYotwArB7jNMOV9WXjnr9+x/m0iHfQoIhQHuoQxOaDRfk4cP3P1dW+oBTZGasjfHsBO9n3lEMZYXr1ammLVgJBso16PPFxEP5MdSj4U3OeVb8ZzUiRfR2VnOwkIRfk89aw6xs+g1LQhr6IGkAu3vJFgMqz4Fl0M= 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=gGRQ/DEb; arc=none smtp.client-ip=209.85.210.48 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-ot1-f48.google.com with SMTP id 46e09a7af769-6f8ef894ecdso611333a34.1 for ; Thu, 30 May 2024 08:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717082070; x=1717686870; 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=etE6dgY3ZZdPAacneXLnj+Gq8AOjqNZk3KGQXXeWybg=; b=gGRQ/DEbi0NqlwgpRoPz9DSzkWT3wseQbS0BKn+LnURYP0WYJ6GZ98uOPVpWjPLmi0 rojs1O0hCNNk0H2TrEJD9n7q3ncvmkWRVWnWHrLcXfBLhl9KpJs/NDD9qNhr4XRVM52P JI6z23QvLPnPa/946ltbv3FGNyvYE88dMXI/caFJCjzSp5y5U8f8lAUedEHGlFG7CW1t KCgLEEl646xPRVwtspYkFVcrRD6IfNJaGlF2cbDYiWLweQ3pMVeoN1YtpgpPAJlzQu2j HfzMTgkcwYemv6xgz1+x2ct+6UqvaDAXu6jZPjW450SFUqRSoLfrD7vq74KN1kaU1LCp yA4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717082070; x=1717686870; 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=etE6dgY3ZZdPAacneXLnj+Gq8AOjqNZk3KGQXXeWybg=; b=EIv7wzlrUHkDAoGSHdricRE15HU836cbNseFRfc0xLCyZHOmoHlErMojaa50ksvTGQ Hd/rM1at7vHXghKdzrhukwHuCUguOozWJ+f6aQdwkmn7yglSfoAAjxk+lDIrkxUmh/jK TY79H1zkyzWX6r3OXBFCrrdTbKITW3oiz4ZN8Tg2Kpa7pYMYua/kLeZ5DIsF7e5R9EK9 9H9EPDXpYQZU4y9YXVvj7IojaGjUw7yVLUbjSOcGt3jNeXyqsWTZHJNraanUvgSy1Zl+ ILlvZjpuuLRcZ4S2Gl3jd3AtPmQG26x790E2DQpecjtUwzWMX+B2pVqHd7ngIng0MztG LgAA== X-Forwarded-Encrypted: i=1; AJvYcCWsNfmYuqu3IYKipdovdJMbz81KCRm5b3U9wqYhVcHobojReScs4mJOrhQZC8i7YHPQFo22WN0mmR+oAZFEi3LpvguS8ONoYNbu6UPp X-Gm-Message-State: AOJu0Yw+HAb/U15UTTnDMMox5Klc7HlZcl7a+51PhlP0qBdaQeHVpCod ngGGRnD7ZAErRGIIJ+4o4ihjxsTK4uwK8YeuY6RMGhAOgzRvhEzYnaly5+xTpZI= X-Received: by 2002:a05:6830:3b0d:b0:6f0:e71c:6065 with SMTP id 46e09a7af769-6f90aec54b8mr2744897a34.19.1717082070067; Thu, 30 May 2024 08:14:30 -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 46e09a7af769-6f8d0de6314sm2803425a34.41.2024.05.30.08.14.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:14:29 -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 v3 2/5] iio: buffer: use struct iio_scan_type to simplify code Date: Thu, 30 May 2024 10:14:09 -0500 Message-ID: <20240530-iio-add-support-for-multiple-scan-types-v3-2-cbc4acea2cfa@baylibre.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530-iio-add-support-for-multiple-scan-types-v3-0-cbc4acea2cfa@baylibre.com> References: <20240530-iio-add-support-for-multiple-scan-types-v3-0-cbc4acea2cfa@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 --- v3 changes: none 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