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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A411C32774 for ; Tue, 23 Aug 2022 06:58:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AAA16B0073; Tue, 23 Aug 2022 02:58:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 659B56B0074; Tue, 23 Aug 2022 02:58:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 522438D0001; Tue, 23 Aug 2022 02:58:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4110D6B0073 for ; Tue, 23 Aug 2022 02:58:03 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 19904A04F7 for ; Tue, 23 Aug 2022 06:58:03 +0000 (UTC) X-FDA: 79829952846.19.4A86CEC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id B420B160030 for ; Tue, 23 Aug 2022 06:58:02 +0000 (UTC) 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 dfw.source.kernel.org (Postfix) with ESMTPS id A0D67614D1; Tue, 23 Aug 2022 06:58:01 +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> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661237882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JA4L7qXfHd5KZACVuoW0urXLaVoDuCIF0bJPQLgio/g=; b=2kjyanj+M5AVUJo9XAa8wjlyStTJDCONtBWNvtvvxLk1oyNVR8JDzBFK1l4lOK3wFvYHm4 /xJpJYAIoNf0hilIwggwRc2/AD2ajeMnvgpcXIUV0zOujg465DAZkkzAG/zojbR0hlKbeQ H7IoM7c3OaDEpUeLwS0ccFyljoqSoD8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=j+SkYAOD; spf=pass (imf08.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661237882; a=rsa-sha256; cv=none; b=2vwG3mp62ObInh6DeM/wyQ083eIORh+GoHuobMEsKIe4vJrtncgQfEA9zpraZlGT78kovf DXwJB/Dcl2yzqB6AkFQPkZNzazepiTrVTXgFBeE0NyN6F90raVz4+onDMR3uGtUdpMZhZO z7z2WiGRiY6YmolBcHbDDYxs0lumzYY= X-Stat-Signature: 4radm6a4q9fduyz4fupo6eppoyswpk4k Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=j+SkYAOD; spf=pass (imf08.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B420B160030 X-Rspam-User: X-HE-Tag: 1661237882-158726 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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