From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E8AF131; Sat, 18 Nov 2023 05:42:54 -0800 (PST) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1r4Lau-00038a-H1; Sat, 18 Nov 2023 14:42:44 +0100 Date: Sat, 18 Nov 2023 14:42:44 +0100 From: Florian Westphal To: Kamil Duljas Cc: Florian Westphal , Jakub Kicinski , "David S . Miller" , Eric Dumazet , Paolo Abeni , Jiri Pirko , Johannes Berg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] genetlink: Prevent memory leak when krealloc fail Message-ID: <20231118134244.GB30289@breakpoint.cc> References: <20231118113357.1999-1-kamil.duljas@gmail.com> <20231118120235.GA30289@breakpoint.cc> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Kamil Duljas wrote: > Yes, you're right. I did not think about it. So if we have a static > pointer that may be resued, should not restore the pointer as at the > beginning? > static unsigned long *mc_groups = &mc_group_start; > > At this moment we don't know how much memory is allocated. What do you > think about this? We do: mc_groups_longs. > > new_groups = krealloc(mc_groups, nlen, > > GFP_KERNEL); > > - if (!new_groups) > > + if (!new_groups) { > > + kfree(mc_groups); > > + mc_groups = &mc_group_start; > > return -ENOMEM; > > + } Seems wrong to shrink when we can't grow. Whats the point?