Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2384381rdg; Mon, 16 Oct 2023 02:47:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmAHVWv8blzY+63evJ+Z24XOwKjLNr5fkaK5yDUTMszy1wRViB56ehODYat5yMgLpdLB7w X-Received: by 2002:a17:902:d490:b0:1c6:19da:b29d with SMTP id c16-20020a170902d49000b001c619dab29dmr33082587plg.44.1697449636493; Mon, 16 Oct 2023 02:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697449636; cv=none; d=google.com; s=arc-20160816; b=RsUs8VkUgiHxNGZ0Jj7fOaf+V7K9HuqvIOXY3tYWmvVmUh7zDFF8PLw/Hftm2FGXAK PPTE4MI1pG6A+OW/YhssrQAXJMZBQv7YOuuzqmAQRD8NqkRiEfsF1E6R5cZeejh9/dFd m5OhOtq+keFF1MTfvqKaTKaIQwHvB/SHGNi51pQXx7x9fTvkWWEnlnld4QuzFQgwhPqb 5QfIvRSiUpMTMYRQRm4SurxgSrECSBgPnGDZVF+O3puJCQurNFfFnMtCDN1PhMJeDUW5 rsMOhs9+3mP2CxZlxcFbci/83gexVw94GGNb8UqReIEKlL8CTkP6Lwa0oScrTHwcO9rM P4Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=D0+r6taFyH+fgxvjyk1ODq9Nj67HjWUkYOptkmVa1t4=; fh=aKgSsLsnbw4gR8XRK6tRBix8a7+wMwXmoE/ZK0Z3p+Q=; b=f57kCzxqB7dTR2NvE4UmcOheIhmIktW0drblPlwyS0FxQuOw41ZXaK9ppQ95NqLMmI n+7C++Of8/80zqmyK0vX0uCTNHgapGZoW8zz2o1rMVJUoS8sGWYTXyyEGBzBRdcmpr6s Oy2GruKSdk2gbNiO0dAv5/ibzvfSo19UXuaz1bAKmfjpFLEHNeRoJMUkNJo1QvXDIpRC Lhb5z9xAO4l15eKjBPcqkJ7xMAijcCfzK86NZ4XUruOj3asvRs+kK66l2qiVoqsf7q9Z AN1cipPdiU5ab5ITP6pV6zxQ0OmaG1tfEaqg9oJVL8nl8ia6Rl0pQJ1g/BTrSoniYGne x6rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="UIOpM/bY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p5-20020a170902a40500b001ca86fa1e1csi902870plq.484.2023.10.16.02.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 02:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="UIOpM/bY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B4EC5807FCC9; Mon, 16 Oct 2023 02:47:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbjJPJrF (ORCPT + 99 others); Mon, 16 Oct 2023 05:47:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJPJrE (ORCPT ); Mon, 16 Oct 2023 05:47:04 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E52E2AB; Mon, 16 Oct 2023 02:47:01 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c4fdf94666so42264651fa.2; Mon, 16 Oct 2023 02:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697449620; x=1698054420; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=D0+r6taFyH+fgxvjyk1ODq9Nj67HjWUkYOptkmVa1t4=; b=UIOpM/bY3wJWOeenNnBL9wnoT0xcq4nnlJW0KcGC/VgN7yyimOGIt2H9S/ICnuQplW XZGGFN3E2LHkF4dCu4B633P8NOxeE9QAdLgY9+b2cwsamMrgo2zQHqo2mxeEegEXPHpN eJ7SUczU2IFMYx9GnoyqOOYXG+JiSMCbtRlSUCc/sosgEC2g7W33sdujw62glofsdECo s+18OqFgtJqizALGk2TptdpVAM2wiGmmVluFW5288E5lWmrqNj+NkEqO6QUfV/ZatR0+ WDZvCPs9oM9LIAbzUTjTljeRJkoN/ZlAox/2GOC+Psv5zSocJYOsfHGA1/YXpIRuqPxP UNdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697449620; x=1698054420; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D0+r6taFyH+fgxvjyk1ODq9Nj67HjWUkYOptkmVa1t4=; b=t3892Xl3hjnsq1d5S95/1weSdLQrMpJ0bH7p5N5gqXu4/4ooDQZIZIoeQ3+WvtpIq1 0QVeehEsPWCPkrtTXQa1uKEyRhmmoUBsIIF/sF0G/e5Q9eEWleKVA1iRe9w5k7XM/WbY qpolpevOl1wYs/vLPgtgKdj+1+ZTq647eZGuaK6e5Ny7SG1PeTfJorfJL7tbqN/TeE9d FE/o6ddZ2KsOelo5Km2NH3mLf1GBZGtID+48mVS8984hq9Pd9L0t/c60o/nNWtyaNhYm 9p+F53ot2u8wJS1NBPA6aSM7pM1doldiZfiL9xcJ2Z8Y1GpKg89aj5yCvNkCH0oNPfzm 485g== X-Gm-Message-State: AOJu0YwzN/ozVLJIxkQkted/JQpti1a3WkPu0gimGlJ2j6FOdpwo99Wi cCvP59CfMmJUvrHx0L6VdXjMVaKg7TP6AA== X-Received: by 2002:a05:6512:138e:b0:503:7dd:7ebc with SMTP id fc14-20020a056512138e00b0050307dd7ebcmr35277012lfb.18.1697449619822; Mon, 16 Oct 2023 02:46:59 -0700 (PDT) Received: from ?IPV6:2001:14ba:16f8:1500::7? (dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi. [2001:14ba:16f8:1500::7]) by smtp.gmail.com with ESMTPSA id c14-20020ac2414e000000b0050309ea3a62sm4471555lfi.277.2023.10.16.02.46.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 02:46:59 -0700 (PDT) Message-ID: Date: Mon, 16 Oct 2023 12:46:58 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iio: sanity check available_scan_masks array Content-Language: en-US, en-GB To: Jonathan Cameron Cc: Matti Vaittinen , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231005163026.2c7707de@jic23-huawei> <751a87c9-a4aa-4e06-1d12-1e2b1a3487de@gmail.com> <20231010110419.00899e0e@jic23-huawei> <0d05bf24-caa6-0f86-b531-22dc08b9cadc@gmail.com> <20231010154734.7728fe2b@jic23-huawei> From: Matti Vaittinen In-Reply-To: <20231010154734.7728fe2b@jic23-huawei> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 16 Oct 2023 02:47:13 -0700 (PDT) On 10/10/23 17:47, Jonathan Cameron wrote: > On Tue, 10 Oct 2023 15:56:22 +0300 > Matti Vaittinen wrote: > >> On 10/10/23 13:04, Jonathan Cameron wrote: >>> On Fri, 6 Oct 2023 14:10:16 +0300 >>> Matti Vaittinen wrote: >>> >>>> Hi Again Jonathan. >>>> >>>> On 10/5/23 18:30, Jonathan Cameron wrote: >>>>> On Tue, 3 Oct 2023 12:49:45 +0300 >>>>> Matti Vaittinen wrote: ... >>>> Other option I see is to just error out if available_scan_masks array is >>>> given with larger than one 'long' wide masks and worry things when this >>>> breaks. >>> >>> That would kick the problem into the long grass. >> >> Well, not 100% sure I interpret the idiom correctly ;) In any case, I'd >> say this would indeed postpone dealing with the problem to the future. > > It does indeed mean that! Sorry bad habit to use idioms in discussions like > this. > >> To the point we actually seem to have a problem. The "long grass" as if >> hiding the problem is something we can avoid by adding something like: >> >> if (masklength > 32 && idev->available_scan_masks) { >> /* >> * Comment mowing the long grass. >> */ >> dev_err( ...); >> return -EINVAL; >> } >> >> to the device registration. ... >>> iio_dev->available_scan_masks = (unsigned long *)available_masks; >>> >>> If we put such an example into the dummy / example driver then that might >>> act to avoid us getting bugs in future + test the fix you have above and >>> related. >> >> Well, at least it shouldn't hurt to have some example - although I'm >> still tempted to use the "long grass" - option ;) > > That is probably a good idea for now. Though we are carrying other infrastructure > to support this eventually and it feels weird to error out on it whilst we have > code to support it (assuming that terminator is long enough). I agree. I think I won't use the bitmap_empty() - because I feel it is unsafe. I'll leave the *av_masks check as it is implemented in iio_scan_mask_match() for now. Eg: ... const unsigned long *av_masks ... while (*av_masks) { ... av_masks += BITS_TO_LONGS(masklength); } This will fail if mask is longer than unsigned long - and if we have masks with zero bits worth a leading long. Still, this won't overflow and it also works for masks which are wider than long but do not have the leading bits zeroed. Balanced act of safety and functionality. This should allow us to safely do: if (masklength > 32 && idev->available_scan_masks) { /* * Comment mowing the long grass. */ dev_warn( ...); } without returning the error. Not perfect, but should be safe and also adds a warning if someone trusts the multi-long masks to work. Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~