Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3209645rwa; Tue, 23 Aug 2022 00:10:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR5GKGMBJmo2LtQ5zQYK/gYDd8D3yGqLoHxcyvhfk8D6TZaW9QTqhDZUUORAH6/8rD/aWLQt X-Received: by 2002:a17:906:7c4a:b0:73d:9279:2c42 with SMTP id g10-20020a1709067c4a00b0073d92792c42mr2870511ejp.597.1661238649682; Tue, 23 Aug 2022 00:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661238649; cv=none; d=google.com; s=arc-20160816; b=uT3YTi1rxzifNS6TH6OyL7QAVCAECKuRAYXS7LU55UHZq7EwRHl9CkJ8qt4rs2auOj 465uddkJnmjU1vHOczHS4ntll+qNT2M6MRCMS/KHdK1EMFqyEKs5GbSA1Go5czYzUj33 8VCClFToatMg/FpFtDAVP1xMRyLUTGdmHsclH0Raha2TFWd7F1wkar7ftuMVDStqaFES 1scGK+tqVq4AqH31c6tMFi/6xj/Y6FcE5lOcXZ8r23T6w3NCRTNt1IqjpZdFm+/dDUrh KVoE/Vh/RJWURw3/PQLsdcl/tqzQswrPIFfFNEXlelQy9UbSggqqX0F5WBEuuY9+8FHR JBnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JA4L7qXfHd5KZACVuoW0urXLaVoDuCIF0bJPQLgio/g=; b=yfMc4auIKgC7qaDkTLcLpbRNl2CAd7p2HVnUXh9UNymKlwD1WwkM+H1OQbRC7Rxoau zVPmylSfWvFks9o2OfhEFXZKDSPLTfjTXtfUr3oca414lz2Aarl8yRTfeoJ45s747jTi 4xs3R7C5Lpph4cSVJLRn/PqdKaP3Q4AUteAs0iLneIhs53Whb8NtqruyOuQr6qjfQvom eVNLvyt5dYDBgWtPZ1wEAPdG9HTMfpWNcBwEUKRb3ropwPRg4TmsNgy9aX7H18gG9bkD jQu0hy3KBAeqIj6ID0u5IxsP+ZfHP85CCZwqzc+O+mrN/hNRDcgFfQ0eEkng45KUl7y8 8V7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j+SkYAOD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402355300b004468df6085fsi1525529edd.545.2022.08.23.00.10.23; Tue, 23 Aug 2022 00:10:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j+SkYAOD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240772AbiHWG6H (ORCPT + 99 others); Tue, 23 Aug 2022 02:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235552AbiHWG6F (ORCPT ); Tue, 23 Aug 2022 02:58:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CFF16170A; Mon, 22 Aug 2022 23:58:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3552AB8105C; Tue, 23 Aug 2022 06:58:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75A4DC433D6; Tue, 23 Aug 2022 06:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661237881; bh=9pREzEtDD8D1Hin9NV/0CXxrHab2zUxM4K/6mcLIWBU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j+SkYAODehhMMoxFqIlBIXttWkdp7KR43X/rkxDkBvTdE3X40dWSaBN6e7w/EQnsJ T9zNc4OiRO9/uKFSKJuH5NjP1la+Rim2tSngiFnlRuy6/RrkSreOgh2DQ01dlrdLDR WsBIohtcynfZtkyv61nmDIfOiqbPxuGVMLz4K0rQ= Date: Tue, 23 Aug 2022 08:57:58 +0200 From: Greg KH To: SeongJae Park Cc: akpm@linux-foundation.org, badari.pulavarty@intel.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3] mm/damon/dbgfs: avoid duplicate context directory creation Message-ID: References: <20220822165236.87421-1-sj@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220822165236.87421-1-sj@kernel.org> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 On Mon, Aug 22, 2022 at 04:52:36PM +0000, SeongJae Park wrote: > > > new_dir = debugfs_create_dir(name, root); > > > + /* Below check is required for a potential duplicated name case */ > > > + if (IS_ERR(new_dir)) > > > + return PTR_ERR(new_dir); > > > > Did you just leak the memory allocated above this check? It's hard to > > determine as you are setting global variables. > > We re-alloc the metadata arrays for context above for this new context, and we > do not re-alloc those in this failure case. So yes, the arrays will have one > more item that not really needed and also not really will be used. > > However, the variable for the array, 'dbgfs_nr_ctxs' is not increased here. > Therefore, the arrays will be re-allocated to the proper size when this > function or other function that re-alloc the arrays based on 'dbgfs_nr_ctxs' > (For example, 'dbgfs_rm_context()') are called. > > So, though the arrays could have not-really-needed one entry that is only waste > of memory, as it's only a small and fixed amount of memory (just one more > pointer), and as the unneeded memory will eventually be returned (by a next > 'dbgfs_{mk,rm}_context()' call), I think that's no problem. This is what I > intended for keeping the logic simple. > > If I'm missing something, please let me know, though. Ah, that makes more sense, thanks. The code was not obvious in that error paths normally clean up allocations that were done earlier. All is good. thanks, greg k-h