From patchwork Mon Oct 16 11:04:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13423027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D844CDB465 for ; Mon, 16 Oct 2023 11:04:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232370AbjJPLEX (ORCPT ); Mon, 16 Oct 2023 07:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbjJPLEX (ORCPT ); Mon, 16 Oct 2023 07:04:23 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11AC583; Mon, 16 Oct 2023 04:04:21 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c515527310so21690071fa.2; Mon, 16 Oct 2023 04:04:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697454259; x=1698059059; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/nDb8K3NJwk1obZ1SsU2lxQGhz5tCjrcotcdhCQHsm0=; b=AUS8P6ThC7Ni6xfq5vKGDZWmAprcI4E9Z2YY7wprmMw1L155luPP4Aw6Vh4SM+Y7Sb OrEE3hKjWPlFGxVwqUV++fTmqQhLmkbVOmc4h1Nsfl503tkMPWM9DjLxuX8l7fvGAgJT frEynMsxyX7/PTJvO2TWxRBeZDl8+YVL73CpUcHlKCL+K7bSrrpvKFUmqC3rMbEmaJ/M cLgKUMzb2zQT1UfQbGPmC11Imk7BZDxiWKZA4KBraa28N6D1imnTKG/u8YOKqnG9oyLP gv437OgdUr+3N24Nqgi/KrrD3BdCEHtFiL/XiM4m31WLQVXgEP5IjhEsSaRbAd2WqQhm QI+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697454259; x=1698059059; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/nDb8K3NJwk1obZ1SsU2lxQGhz5tCjrcotcdhCQHsm0=; b=j8hRtZbVh8izNSvLGXVhqYvks8KmAElBWX841ocN63Y9FQTSi/S0XkZmhpdRN3PcLP OMT5elgENw9PCKgE2ZGnLgobk1Grb+7htmAaNaFCfve5FW8gddsUqAUhcY0jZzLZnMlS wJCKuMAtRfkXCT8xtxcejltd6VBqxjdbTQbzVj9og+c/JG7U3Fb/Q/F4M5g5zza2e+Ml GUNvVkKRjp3aXpu8o42hklzpdOfnOEf9sAc2OXBlqTDl5S7IhJN5QyKT7ZNX2xIjRAO2 RrjoLv7NHa4HnuuxMZnHcIw3PC2A8RMGUZpjH6/3dP+TKioBkxrW7LGa424AjMCiFuxp sALQ== X-Gm-Message-State: AOJu0YyNfII6RC7d9tHkVo5tAGtA9lfNZDo3+LmLV2djRUugJ20qXPC7 aspbZvO0wqeW0N3PoPO9Tg0= X-Google-Smtp-Source: AGHT+IGIxHL+5o9bgkt0Xh5P7TXY28VMMohbmqGu7TL/OAqQtRFVCNxUeo1t6Rxc1Yb5xhc7Pk4chA== X-Received: by 2002:a05:651c:1a24:b0:2c5:1bd9:f95c with SMTP id by36-20020a05651c1a2400b002c51bd9f95cmr3540664ljb.53.1697454258987; Mon, 16 Oct 2023 04:04:18 -0700 (PDT) Received: from dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi (dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi. [2001:14ba:16f8:1500::7]) by smtp.gmail.com with ESMTPSA id e20-20020a2e8ed4000000b002bfff335ca1sm1267503ljl.79.2023.10.16.04.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:04:17 -0700 (PDT) Date: Mon, 16 Oct 2023 14:04:11 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/2] Sanity-check available_scan_masks array Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Sanity-check available_scan_masks array The available_scan_masks is an array of bitmasks representing the channels which can be simultaneously(*) scanned by a driver from the device. Following special characteristics apply: - When IIO is scanning through the array it will use the first mask which can be used to scan all enabled channels. This means drivers should order the array in the order of the preference. This does also mean that a mask which is a subset of a mask located earler in array will never be used because the earlier one will be picked by the core. - Masks wider than size of long are supported only to some extent. The code scanning through the array will interpret the first mask with first long zeroed as end-of-array terminator. Changing this behaviour would make mask-arrays for multi-long masks to be terminated by more than one zero long. Failure to do so would result kernel to read beyond the array generating a potentially hazardous bug. Add a sanity-check to IIO-device registration emitting a warning if available_scan_mask array is misordered or if mask width is larger than a long while available_scan_mask-array is populated. Currently there should be no in-tree drivers with available_scan_mask populated and mask wider than a long. Revision history: v1 => v2: - Add patch 2/2 documenting why iio_scan_mask_match() checks only a long worth of bits while searching for the end of the available_scan_mask-array. - Styling of patch 1/2 as per comments from Jonathan v1 and related discussion here: https://lore.kernel.org/lkml/ZRvjuZaQWdZw1U1I@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ Matti Vaittinen (2): iio: sanity check available_scan_masks array iio: buffer: document known issue drivers/iio/industrialio-buffer.c | 16 ++++++++ drivers/iio/industrialio-core.c | 63 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+)