Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1176740lqa; Sun, 28 Apr 2024 23:40:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzkjiFx1YAlAUIAZEFT6aGyRgu7GOutyw8vpFlSAv8RQaIG4Wdk7PQo4QwT7u9RhUfK1UJjl74ne0OoKXd7CxnkmTKebtmkklYeWFZaQ== X-Google-Smtp-Source: AGHT+IHnFHlJF/GlPG4xVGzk+EdNmXzKWvtM5RHBjcAux7jyCHY91UnfpipFKegO0hmTq+WxmqJ+ X-Received: by 2002:a05:6214:e45:b0:6a0:ae32:34c5 with SMTP id o5-20020a0562140e4500b006a0ae3234c5mr9827253qvc.14.1714372855229; Sun, 28 Apr 2024 23:40:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714372855; cv=pass; d=google.com; s=arc-20160816; b=BOC9DMDSBkSqTz/ajakgBWrqzTlZFuQPbhOFvjivtsBsbS7ZwerrtZminiuZwFEHxX K7Eyriv/+eVvhkQ4jTmx2ktW4MCbo0vimWYuHZtYIQ9Jpu+wb0kFcWVR1ajjXrEDw71M oLkOlSOSZTMsm9cUctoru5RJ0WOhp3nMqnFJwdwPnluRj8Ydy5Erb7PLIC8A0xESWB7c Y68xJbnNhyeSYCsIEDQazdImeRJWCOE8sv3S4vxhe8f4Hj+E9xTGR30FhkGVHkRM5+7+ 1B9aazx0z1J/JSB7L/wECJ2toR+jdEBGyKJvF7wr+jbVkxG5fkhsVaAEzSOCKphj2qcJ rT/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=+ySN0noyUH14atcen2ygoeKf0I5NwKf7EhALfl5OZZU=; fh=nXW8KL9qInx5e3vsNVaEBuDo7sRbrFqvcRFqtcxnulw=; b=VCipOH34MpJzEklf8zrWFPloCxRkZZ2Zdh7MljrwKwTbiCYCaJMYcPh6YiacTIBIDK SWchhAX9GwsFCD/9ZXGtfu5Q63soEdlG3rsyiGkTA6Uf3c15BJeYKLGH3+5lSo2JSDEF 92FO3Ixa+QSfOxSaGzZ9KkHt/tq3VrhSKhHWVn5tLfYjhxnqGOMt3SEeBZR4YZoZAqwt Cwd+Lt9UjVGoNxcygdUhkmv//binf/JYdGnQ2LADBBTcQtYV71a4XtZMV/UqaTWJiD1e 9R3NOQsa8gSz2zK5gWFPtpEew5dk+LYHCQ5kzQ/4myooXL/35n2qhuW4d/8TwNDpUhbD QtNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F2nJFGMC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-161815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161815-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id hf9-20020a0562140e8900b006a0c91dbd86si2832619qvb.39.2024.04.28.23.40.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 23:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F2nJFGMC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-161815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161815-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EE6BE1C20F44 for ; Mon, 29 Apr 2024 06:40:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5A75111A3; Mon, 29 Apr 2024 06:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F2nJFGMC" Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 6F5E710A09; Mon, 29 Apr 2024 06:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372848; cv=none; b=kzE6QTsHgflVEz+wWQD9bnO2mJHLxD9yPtvcaFvTwDgR0dHTnKvj+lYzeNTQDJSK7XEs5wxhavA7uuDNebTXiNNncViqWK66/fzhSJoZ240CF5WV5aP9824m4LxS08O/eqdMIAWI/ARDHhXROyLFaULezZxebxOK/7yeulv6Sug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372848; c=relaxed/simple; bh=fgvAz0sLTTktebTn14gaVVatU6mFkIDYuROOi6e1HvE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LEUOrpAk5WTZUhCYAlOWtgBuBJpKKv22FiCwFOlGm/BIf9MYH2775L4qcJ5BWI2qR/uHsnKivogd3gyOQAFr8aYpcKJc+ss/gOgIwAtYOIDvBKh7uJ1i3w3Z7T4jvNeho9p/lnRU6X5xiYEsKLVrKAj5cG1iOeWbS8y9db6J4pY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F2nJFGMC; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2dd615b6c44so43351971fa.0; Sun, 28 Apr 2024 23:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714372844; x=1714977644; 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=+ySN0noyUH14atcen2ygoeKf0I5NwKf7EhALfl5OZZU=; b=F2nJFGMCTq2EE5tS2mgJ2H0mB/otH8KqS3dBVAIL8vqcsLRdwA6Otsy5mN/x84HJuG Afxf7rwEttY52y3ZVPOz0AqtJN8DRQxguTabcoMkYnPweKhyQA5PMlptZmXzIYPRi3f1 h9M9CyRfIKBICzv4H8HiOmpukECEioIYQMtPZpLBquOKydLxfRqm1coSnhriDCAMRkAU iDvHTWqvksbnJzWEn2QUf+AsVq73Y9yc8x0wsbuNs4BEb8TXXEYuAr4UTIfeaPzDdpTS UrVw6f/sb4fqnHlQih7ILDw6pqm1aq3XvXfz4cZgfnTIseitJZGMJ/fvKc31TnKl7Auj BVxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714372844; x=1714977644; 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=+ySN0noyUH14atcen2ygoeKf0I5NwKf7EhALfl5OZZU=; b=wrzSFGdbGkitKmLcRwZL4c1bJpFV/4PGkO14UHsz/R1QZ8hLjbKTiwPMPFEX37lGZb 42UJ+CAmu+zVgpxNb2JKfZzKekWt771nv9bKDMInwRSFqPYMgcI+Qq25usgIYhCi0NiI wCCTQoGGfuR6eE78KUOhWGLtsxrADehrfnPi6Fy5d1BvDlmsFNXYZM+LNv0PPzozXOya mhCsxwuZeenkBRl0jcis4h+bvbgjLWQM5oUUFBmKYOWp6IAUOOxM9AB+a3u4g/AYAp/c z0TJl+VkYpWpUOCMIwlzSzNYhN0pCmyotZhHnFW1Vn530clTLP7im8/+HNVwiThHjTHe MNag== X-Forwarded-Encrypted: i=1; AJvYcCW0sjZ9KzUegFFWay8BIuwqRCGp3dKmwu5iVdaCJwpQPRQ3yHmhmGkgKa2Xt60DC3NCc4fMjod7qhbQrwKBgn2ngxEZZa9heUBMi+JAYXWhp4LChxTPH62PBm2J5Q+U8+zJO84egXPA X-Gm-Message-State: AOJu0YwuKfiYibiUwJJ7FZ0y+uH5ZvnMnXvvHHefLlSr5LLWBYKoBZW4 qFQuC5KMWEE/5Oc79w+Hj793kI9/Uj1rP+vvhsHDg095Or5tYPJJ X-Received: by 2002:a2e:a789:0:b0:2e0:9ab7:22af with SMTP id c9-20020a2ea789000000b002e09ab722afmr363960ljf.53.1714372844359; Sun, 28 Apr 2024 23:40:44 -0700 (PDT) Received: from ?IPV6:2a10:a5c0:800d:dd00:8cfe:d6e7:6701:9dfd? ([2a10:a5c0:800d:dd00:8cfe:d6e7:6701:9dfd]) by smtp.gmail.com with ESMTPSA id e20-20020a2e9e14000000b002df37b8e73bsm1094215ljk.37.2024.04.28.23.40.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Apr 2024 23:40:43 -0700 (PDT) Message-ID: <142a905d-f0e8-487e-a8db-ee1ded6da21f@gmail.com> Date: Mon, 29 Apr 2024 09:40:43 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] iio: Fix the sorting functionality in iio_gts_build_avail_time_table Content-Language: en-US, en-GB To: Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chenyuan Yang References: <3d98589455726e812cf2ad2610f7351ee2b93b07.1714371936.git.mazziesaccount@gmail.com> From: Matti Vaittinen In-Reply-To: <3d98589455726e812cf2ad2610f7351ee2b93b07.1714371936.git.mazziesaccount@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/29/24 09:29, Chenyuan Yang wrote: > The sorting in iio_gts_build_avail_time_table is not working as intended. > It could result in an out-of-bounds access when the time is zero. > > Here are more details: > > 1. When the gts->itime_table[i].time_us is zero, e.g., the time > sequence is `3, 0, 1`, the inner for-loop will not terminate and do > out-of-bound writes. This is because once `times[j] > new`, the value > `new` will be added in the current position and the `times[j]` will be > moved to `j+1` position, which makes the if-condition always hold. > Meanwhile, idx will be added one, making the loop keep running without > termination and out-of-bound write. > 2. If none of the gts->itime_table[i].time_us is zero, the elements > will just be copied without being sorted as described in the comment > "Sort times from all tables to one and remove duplicates". > > For more details, please refer to > https://lore.kernel.org/all/6dd0d822-046c-4dd2-9532-79d7ab96ec05@gmail.com. > > Reported-by: Chenyuan Yang > Suggested-by: Matti Vaittinen > Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") > Co-developed-by: Chenyuan Yang > Signed-off-by: Chenyuan Yang > Co-developed-by: Matti Vaittinen > Signed-off-by: Matti Vaittinen Huh. I had never before sent a patch with co-authored tags. Just to ensure there is no misunderstandings - I did send this patch mail. I added the From: tag as was suggested in: https://www.kernel.org/doc/html/latest/process/submitting-patches.html I am afraid mutt picked the email sender from this tag - which does not fee like correct thing to do! Sorry! I did not intend to impersonate Chenyuan! Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~