Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6297614rwn; Tue, 13 Sep 2022 01:59:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xz5Qt9JGDd8Qk9vtCzB4wpTcln/Fr61waEveriqy7+SB3LiWnhQqAdn9L8lJ2EBCvTp3v X-Received: by 2002:a17:902:bb97:b0:175:6721:2c34 with SMTP id m23-20020a170902bb9700b0017567212c34mr30881255pls.146.1663059543566; Tue, 13 Sep 2022 01:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663059543; cv=none; d=google.com; s=arc-20160816; b=gYq0yqYNOZNmYW2Xb3Et7dVYE/13cwJRJxJ0lNMjq2ioofpSyV9Q8HuWY7X7leEF8A bhOg6v3yq70MpK8idzC808nWlqr+OTWvvFIaa1PerkJiDx3G+QcmQWwz6Br3vyPWFCOw wq6z6aJ/t63o4GI9s371rp7Kj5oTZ7F3XllQoLJrpQ9rdngu2ez/24Ok2oo/MBhH6AM1 a0osaYrUx/ssZXhg2AwWVuuhZEZ99cLMoCLMaZyaDyb8qlzTff/ak0B/VB3rqAVMqnUM 41apKwtYGVPO9NhlmIZrC8PWLLP+FYQQ7YD/fKNtw9v9UvbsRuO7/n8lzkTfTX7RSizJ VvnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:to:subject:message-id :date:from:in-reply-to:references:mime-version:dkim-signature; bh=ivmnXTLvhTwmbAEp7t6pe69Pq/r2wv5rtccxOKjcfIg=; b=nC1MMiqPf398HZ2EpIiu9CVh6kT8pvNN91F/KDTgLEHgNE2IG/LGjtn50j1L8SMwPm kcG9jeDozn4g9jx1xo5cABxLIgC6dV8iCU5qeHdmD1sKIsaiHELoGkUj9J0n7RbOlW39 0oWN0ad7Gs+eAXu5eOLTC/WbaYiGEIx3z9zE8+fbZ4e8+439oxaDZHdBVtB8GoVSCYM2 o6Y4RZ9GyA9LJXvFQ9UGSuLWCi0o83oOVvAZ3VYy0xoqJ7WkAwC8eYGZ9ZTJMj2MkQoT jS9cKAnqAlG5QU28duE64qnNu14d0+6RGvziKudhWovzU+zjEOPLHrHVaAQl5EvOq0aD bUow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bmS0Ji8s; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a65430b000000b00434eb9eb8fesi11583052pgq.266.2022.09.13.01.58.52; Tue, 13 Sep 2022 01:59:03 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bmS0Ji8s; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbiIMIgd (ORCPT + 99 others); Tue, 13 Sep 2022 04:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiIMIg2 (ORCPT ); Tue, 13 Sep 2022 04:36:28 -0400 Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B965C57E2C; Tue, 13 Sep 2022 01:36:23 -0700 (PDT) Received: by mail-vk1-xa29.google.com with SMTP id b81so5461858vkf.1; Tue, 13 Sep 2022 01:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=ivmnXTLvhTwmbAEp7t6pe69Pq/r2wv5rtccxOKjcfIg=; b=bmS0Ji8sRmRAjbdRpP6CyIH9JBqW82fXDxz638KWlN1c/c+XjhS67p6q24DOjYO985 Gt4bgOGZrLgfRj3ExGF5aNhmPosmuypV2qQTYcarOmSD/Z/l9e87ZSTsi8Wo7Lbs7FdG w2+rLtem3qhcwTNq3USzP9nMiWmkUOtnDCs35sjltJNRlnKKLabKxHXggt5ozZVBdXWp job1RxSaL2PomDUUal7JY0IyYVh79Kygdam3cFB5UB8EXs2XGEVC1KIAgzOVFK1bLMqp 7gDt+Ypn/1aEPUGBP/udYVGjvApddz62bce4y/3/MSFH0phSHTJLwmqFqWiyCRulv0vf J4/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=ivmnXTLvhTwmbAEp7t6pe69Pq/r2wv5rtccxOKjcfIg=; b=OWQeLyAScPmiUOpINgCLxj8u0m9/bO6qnGpX11J+ALEYm765oM0Th9uVOZNUuwXlpw 8XNZHXgBVss4jipVFLB6HGEH0nkuFpxrjTOJWmLgRqBkW7UxbX3EwZnFrLv6ZaBRSIsH biBoAFQNr8kNcE3gVAbBql55JAR+fEIrtXR5KAPDMpxnGSar9jHMoEKJHmC2tp69iQdp 8HT3eRswTIrWQ9Ey9G/z6lwDiYYevek/LZmebvmDSqPnGxs2oSaH51gUMnGA6JbmrkYK Sv7yRc170fle/jwn+yZ/FjyAbxK3cq+uJ6JTyGEruWwh2haK4qI2BEYwtMQaoY992RTH KXYw== X-Gm-Message-State: ACgBeo19MbsxVukMstXimBgdUfk3gkcr84lfhPf25kmbZsxB7PWzD+FT wdhzGQXXu5nCv2/mgR8lq8x8FeEbJgh6H1lyTkQ= X-Received: by 2002:a1f:b254:0:b0:345:87e4:17fb with SMTP id b81-20020a1fb254000000b0034587e417fbmr9714431vkf.25.1663058182771; Tue, 13 Sep 2022 01:36:22 -0700 (PDT) MIME-Version: 1.0 References: <165590120140.1149771.2257818527859865760@Monstersaurus> <4883f0a7-6a1b-31bd-33fe-db8f6dcf73fa@selasky.org> <085b9025-bc23-37d4-d430-afc432b4d783@selasky.org> In-Reply-To: From: =?UTF-8?B?7Jyg7Jqp7IiY?= Date: Tue, 13 Sep 2022 17:36:13 +0900 Message-ID: Subject: Re: [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c To: Hans Petter Selasky , Kieran Bingham , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, mchehab@kernel.org, 0215yys@hanmail.net, =?UTF-8?B?7Jyg7Jqp7IiY?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 Dear Hans Petter Selasky I understood your points. Thank you for your kind explanation I found that the buffer size is 65535 like below source code. The 65535 is not the power of two. So it can still be a problem. ... #define RX_BUFFER_SIZE 65535 ... rxbuf =3D vmalloc(RX_BUFFER_SIZE); ... dvb_ringbuffer_init(&ca->slot_info[slot].rx_buffer, rxbuf, RX_BUFFER_SIZE); } ... 2022=EB=85=84 9=EC=9B=94 12=EC=9D=BC (=EC=9B=94) =EC=98=A4=ED=9B=84 9:36, H= ans Petter Selasky =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > 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=3Ddvb_set_pesfilter&type=3Dcode > > cat << EOF > testX.c > #include > > int > main() > { > int consumed_old; > int consumed_fix; > size_t idx =3D 3; > ssize_t pread =3D 15; > ssize_t size =3D 256; > > consumed_old =3D (idx - pread) % size; > > consumed_fix =3D (idx - pread); > if (consumed_fix < 0) > consumed_fix +=3D size; > > printf("old=3D%d new=3D%d size=3D%zd\n", consumed_old, consumed_fix, size= ); > > size =3D 254; > > consumed_old =3D (idx - pread) % size; > > consumed_fix =3D (idx - pread); > if (consumed_fix < 0) > consumed_fix +=3D size; > > printf("old=3D%d new=3D%d size=3D%zd\n", consumed_old, consumed_fix, size= ); > > return (0); > } > EOF > > cc testX.c && ./a.out > old=3D244 new=3D244 size=3D256 > old=3D244 new=3D242 size=3D254 > > So either push the suggested fix, or block non-power of two buffer sizes! > > Best regards, > --HPS