Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1164239rdb; Sat, 18 Nov 2023 05:43:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3AAfDbj/tV3cnVxoZKLsLhOLRb8I6jZOok37wlqTTyVtFmFZYcIt8zSoDe06UxcdjHTpJ X-Received: by 2002:a05:6a00:2314:b0:6c6:a46f:25f3 with SMTP id h20-20020a056a00231400b006c6a46f25f3mr3350172pfh.13.1700314991051; Sat, 18 Nov 2023 05:43:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700314991; cv=none; d=google.com; s=arc-20160816; b=ZFU8a2G3i8QDSNk3uDD5hbgOtkPS/CuVwB8u/2j5vqj6D5dWluNQZsHQELHbNOKgrc lU3f6wHcYVp9c9j7jttaSamkL7dHNqR2qen4dsjurUZtIugoK9nrYfUdBFI8kEcj64dE pHxVahFloahlV2GaUiFHXedjW7KjVhIzLrYSYr+hJRykHYBKIOzw6QxhuVcybRfI8zBI 60Yqmt9eySbdlld4iQiSDOllwyvBn6DTX3NWgK/WchFygrVFXAeqZEt8NHq6c6ZS7RGA cf7otxniD65rmIXjR8BarMl8Bxt/YaGsP55JnymEp162z69qteH5cEdUIt4x6aLOQOAC 112A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GGvD5jLbti4+VHrH0SuciyxTevlaP8qKaaJryI5i5Y0=; fh=0+XqugDoAHpCtZU1zoWU5DLb+/FrEMAXT8AeukDUIXo=; b=tLXUIrEUkHlureBmFXVFB7+5jTgRYojJ0PfDiazmLA2+LC1Wrb1vLwTcJDRPhQMqQ5 bymBUXLRsUUzqyDclE6xqny7i2JrUzKi/kJRSrCD7Zn2ah6nOIhKLMf9IrFbTAXVFP72 mo0d3t5KTTiIjyv6jGmy3H4Gtbqa71XUoUN2pTg1lo4YpS7faE+A9lgMMahPjHtS76Jo 1seBG/7QCzuIEtZdOlv1Wa7NP1MN535lu8u/zWh7DgfJzS8cpR34fPgd/a+tJ+f290Ci oIbFypYLbWj2QLfXpja5nOmPni1Z2Nwgmnp9KRL5WC9Tt4B7TvXsGabQotDk0jj3fxet 4Q+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f13-20020a056a001acd00b0068fe9c452acsi4416625pfv.376.2023.11.18.05.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 05:43:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CF3138045BF1; Sat, 18 Nov 2023 05:43:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229687AbjKRNm7 (ORCPT + 99 others); Sat, 18 Nov 2023 08:42:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjKRNm6 (ORCPT ); Sat, 18 Nov 2023 08:42:58 -0500 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> 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) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 18 Nov 2023 05:43:10 -0800 (PST) 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?