From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EF9AC433FE for ; Wed, 13 Oct 2021 09:17:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E60960C4B for ; Wed, 13 Oct 2021 09:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239100AbhJMJTV (ORCPT ); Wed, 13 Oct 2021 05:19:21 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:28928 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239072AbhJMJTS (ORCPT ); Wed, 13 Oct 2021 05:19:18 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HTmyj18T8zbn7Q; Wed, 13 Oct 2021 17:12:45 +0800 (CST) Received: from dggpeml500017.china.huawei.com (7.185.36.243) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 17:17:10 +0800 Received: from [10.174.178.174] (10.174.178.174) by dggpeml500017.china.huawei.com (7.185.36.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 17:17:09 +0800 Subject: Re: [PATCH] iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask() To: Andy Shevchenko , Joe Perches CC: Alexandru Ardelean , LKML , linux-iio , Lars-Peter Clausen , Jonathan Cameron References: <20211012092513.1349295-1-yangyingliang@huawei.com> <61c28865036cd40a96f2d1bb4c27fbbb08c2d3a5.camel@perches.com> From: Yang Yingliang Message-ID: <04c752b5-3814-34d0-82e4-9d0d46af433f@huawei.com> Date: Wed, 13 Oct 2021 17:17:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.178.174] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500017.china.huawei.com (7.185.36.243) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2021/10/13 4:58, Andy Shevchenko wrote: > On Tue, Oct 12, 2021 at 8:55 PM Joe Perches wrote: >> On Tue, 2021-10-12 at 23:48 +0300, Andy Shevchenko wrote: >>> On Tue, Oct 12, 2021 at 8:43 PM Joe Perches wrote: >>>> On Tue, 2021-10-12 at 23:30 +0300, Andy Shevchenko wrote: >>>>> On Tue, Oct 12, 2021 at 2:37 PM Alexandru Ardelean >>>>> wrote: >>>>>> On Tue, Oct 12, 2021 at 12:18 PM Yang Yingliang >>>>>> wrote: > ... > >>>>> I prefer to see >>>>> >>>>> - for (; unwind_idx >= 0; unwind_idx--) { >>>>> + while (unwind_idx--) >>>> Not the same code as unwind_idx would be decremented before entering >>>> the code block. >>> It's kinda cryptic what you are pointing out. >> Not really, > It's. It lacks the very same "additional" words to explain what you > meant and why. > >>> What's needed additionally is to change >>> >>> - unwind_idx = iio_dev_opaque->attached_buffers_cnt - 1; >>> + unwind_idx = i; >> You left out that 'additional change' above from your reply. > Yes, that's true, but it took some time to decrypt your message. > >>> Of course not. See above. The usual pattern is >>> >>> while (i--) >>> do_clean_item(i); >> Of course, but that's not what you replied. >> I was merely pointing out that your reply included a logic change >> converting a loop from for to while. > I expect that developers actually think about the changes they do and > double check what's proposed by reviewers. If they just copy'n'paste > whatever others propose, I wouldn't take any patch from such a > developer. I think in alloc path is using for loop, and in error/free path also using for loop is better to read the code. >