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 633D7C433F5 for ; Tue, 12 Oct 2021 17:43:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C5976109E for ; Tue, 12 Oct 2021 17:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232865AbhJLRpa (ORCPT ); Tue, 12 Oct 2021 13:45:30 -0400 Received: from smtprelay0034.hostedemail.com ([216.40.44.34]:38512 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231945AbhJLRp2 (ORCPT ); Tue, 12 Oct 2021 13:45:28 -0400 Received: from omf11.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay08.hostedemail.com (Postfix) with ESMTP id F267B182CF669; Tue, 12 Oct 2021 17:43:25 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA id D433120A29E; Tue, 12 Oct 2021 17:43:24 +0000 (UTC) Message-ID: <61c28865036cd40a96f2d1bb4c27fbbb08c2d3a5.camel@perches.com> Subject: Re: [PATCH] iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask() From: Joe Perches To: Andy Shevchenko , Alexandru Ardelean Cc: Yang Yingliang , LKML , linux-iio , Lars-Peter Clausen , Jonathan Cameron Date: Tue, 12 Oct 2021 10:43:23 -0700 In-Reply-To: References: <20211012092513.1349295-1-yangyingliang@huawei.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Stat-Signature: z9zzireukwma57cfoj7sp1d5aw93oafd X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: D433120A29E X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+7/cZM/LWiim6mvI2uBZUhz4Od5CT6vMA= X-HE-Tag: 1634060604-209060 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: > > > > > > When __iio_buffer_alloc_sysfs_and_mask() failed, 'unwind_idx' should be > > > set to 'i - 1' to prevent double-free when cleanup resources. [] > > 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. You'd want do { ... } while (unwind_idx--);