From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425108AbcBRFfu (ORCPT ); Thu, 18 Feb 2016 00:35:50 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35132 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424699AbcBRFft (ORCPT ); Thu, 18 Feb 2016 00:35:49 -0500 From: Rasmus Villemoes To: Srinivas Kandagatla Cc: Maxime Ripard , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: [PATCH] nvmem: core: fix error path in nvmem_add_cells() Organization: D03 References: <1454965469-6141-1-git-send-email-linux@rasmusvillemoes.dk> <56C45016.2010806@linaro.org> X-Hashcash: 1:20:160218:srinivas.kandagatla@linaro.org::t43KftwdTbSwiskm:000000000000000000000000000000016bh X-Hashcash: 1:20:160218:gregkh@linuxfoundation.org::9QEBwEVcxJ/P0SY8:000000000000000000000000000000000001ebh X-Hashcash: 1:20:160218:linux-kernel@vger.kernel.org::7M6LOyCPclXMQxgJ:0000000000000000000000000000000002SaA X-Hashcash: 1:20:160218:maxime.ripard@free-electrons.com::4a+Bkjf40ql6cv2D:000000000000000000000000000004rJ9 Date: Thu, 18 Feb 2016 06:35:46 +0100 In-Reply-To: <56C45016.2010806@linaro.org> (Srinivas Kandagatla's message of "Wed, 17 Feb 2016 10:48:54 +0000") Message-ID: <87wpq2h971.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 17 2016, Srinivas Kandagatla wrote: >> err: >> - while (--i) >> + while (i--) >> nvmem_cell_drop(cells[i]); > No, this will not work. > > 3 issues, > > 1> If we enter this err path from nvmem_cell_info_to_nvmem_cell() > failures, you would be accessing already freed cells[i]. > > 2> accessing un-allocated cells[i]. > > 3> you would be trying to drop cells which are not in the list. > > > This is what you need here to fix it correctly. > > while (--i >= 0) > Sigh. http://thread.gmane.org/gmane.linux.kernel.mm/146058/focus=2149595 TL;DR: They're equivalent. Rasmus