Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp5204970rwn; Mon, 12 Sep 2022 06:05:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR7a/2J6vbKdlgeGigsVMCFUYAR4D4UjixD3D0CCzkr3Xg3QVIFuCeRgxHYfkbiPv5Pl9awm X-Received: by 2002:a05:6402:54b:b0:44e:ac69:c617 with SMTP id i11-20020a056402054b00b0044eac69c617mr22140868edx.64.1662987931464; Mon, 12 Sep 2022 06:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662987931; cv=none; d=google.com; s=arc-20160816; b=yYRUnoprZiShPpSgF8+4cLUk8MDQAs2jiZeYSFxq7FJIVnepuicyJp6ldSbPMYqH8f AivXVJVF6woVuz9hEVTsBIyUKzlMFaEEioOGruIquPewVlX+d8kX3aoUyOo3gNTML9x1 BjZJlpXC2OgKVhxIDbrLS8YbHJ0Kqm5VTw6zx4oPmQMAITaw/pdzcbUqM3BE/1SCvFcG Pn4XwvyzWF0ilI97/WHm8DhqPqgAnFo5PP1Ey15LpYnjemW2w98j2bs9h5LIVUDNqUO/ jhffPctjh9VLVMqWR0gKp3N+gPr/9qYQTkEvAREKkvsHCD5fR/8NIsQePKdBA4iaYKPJ RGww== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=61dkhBIFwqtiD6mz9iglp5m8o5Aw1CuVMOvzdO4/gNI=; b=FIkR3Fq+75P5hWWOakHKgcPYUJKnE3M1Pl2m+1D535TTXnkD1h8X80W+GZJH5AQJz8 vWn98lyJ1yw8LUWT54Zpvrl9kHNzjPVyBydH5w0KERNulP1VLJYiSjPcGQ07HGCyF5OW 9jALKpLBGLvjT3C7Zwj7Mvphw2qU5Fp7ycAODgu0Ot35rWoEPnF28bTo3la3Ewud22lb BreiH+Tn7Ib0pYngPBIyDq0jTkBh9NaN66Krb6t4Bio2avQSRMYoRm6YpUfKT2QD4r5h pKYLObXtUgvv+OWNk75J7dX3/zQXECX8qA3JUKAE+vCJmZ0fDYMzHUd5+s2mBsJydcD4 lwgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp6-20020a1709071b0600b0073da0ce043csi7941132ejc.619.2022.09.12.06.04.52; Mon, 12 Sep 2022 06:05:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229748AbiILMgV (ORCPT + 99 others); Mon, 12 Sep 2022 08:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbiILMgT (ORCPT ); Mon, 12 Sep 2022 08:36:19 -0400 Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE07920BD7; Mon, 12 Sep 2022 05:36:17 -0700 (PDT) Received: from [10.36.2.165] (unknown [178.232.223.95]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id BCB79260276; Mon, 12 Sep 2022 14:36:14 +0200 (CEST) Message-ID: Date: Mon, 12 Sep 2022 14:36:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c Content-Language: en-US From: Hans Petter Selasky To: =?UTF-8?B?7Jyg7Jqp7IiY?= , Kieran Bingham , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, mchehab@kernel.org Cc: 0215yys@hanmail.net References: <165590120140.1149771.2257818527859865760@Monstersaurus> <4883f0a7-6a1b-31bd-33fe-db8f6dcf73fa@selasky.org> <085b9025-bc23-37d4-d430-afc432b4d783@selasky.org> In-Reply-To: <085b9025-bc23-37d4-d430-afc432b4d783@selasky.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mauro and YongSu, Answering my own question: The reason nobody has triggered this yet, is because the buffer size used is power of two. Because unsigned modulus is used, the result becomes correct. See below. But if non-power of two ring-buffer is used, then the result becomes incorrect. There is no block for non-power of two sized buffers. See: https://github.com/search?q=dvb_set_pesfilter&type=code cat << EOF > testX.c #include int main() { int consumed_old; int consumed_fix; size_t idx = 3; ssize_t pread = 15; ssize_t size = 256; consumed_old = (idx - pread) % size; consumed_fix = (idx - pread); if (consumed_fix < 0) consumed_fix += size; printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size); size = 254; consumed_old = (idx - pread) % size; consumed_fix = (idx - pread); if (consumed_fix < 0) consumed_fix += size; printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size); return (0); } EOF cc testX.c && ./a.out old=244 new=244 size=256 old=244 new=242 size=254 So either push the suggested fix, or block non-power of two buffer sizes! Best regards, --HPS