From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84C423A4F50 for ; Wed, 5 Aug 2026 01:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785895177; cv=none; b=uHbdz8qpbQmZHgLEPCRFeyw7iQg7wy5eLJ+9yr3WIx7ZFsiAMgl7O4kpP7FM4G6Wge9JZMFMjHMpZhc7cEZn/jFfV6gKeOO7mmQ/ptvZCDcegI1HDUzNwb7j1MDuW4aJ4yBHDNz32Jok99Ccyx5cObg2D/cd8kEirH3DES4PMEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785895177; c=relaxed/simple; bh=KT6axYmN2v25yhzuUfrfmM1ZblAisy4rDuKzbh7iiCA=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References; b=Yhl11Z/QAlLySwHezLJFlIef7/jZjNz1xcVSvSNB289HicEq1tlUxKlk7Oit+ZaW9haReB7Z//jvdFxKiJZ3CAOWsegy7l/onm9vZl30denFTgexrzPlEYmmV0GGe3YefTNFPPF3dfpujtAWE3uT5MFlY7Me4SEogXPuKaT+NWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IHYhOyDi; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IHYhOyDi" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2cfff5f88dbso6992655ad.3 for ; Tue, 04 Aug 2026 18:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785895176; x=1786499976; darn=vger.kernel.org; h=references:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=RsSvF0ThsYwF5rKvJPenXthbv4vP7R634B7PFbVoBfw=; b=IHYhOyDiUsrISQSPWIjVZK0IC1ChR9Gw+DKRUHXEBrhqSYCKu63zeTWbMy8ZB3Ol/l TSBUq0CZkXq2thf94+gEC7YkuXlco60ZwM4QcqNVwVm4phGc5pjo7hsgPQIt9yeOOZ4K IE4hnDrOAsSz1qlr5FxmosVIyEJ/dXBRJHBAfFvYI41i6ADL186O2dUnSXjps2s+GCqQ CV3HvyfCRoaK1F0ktsaJ93qNmcf8Cga/pXMYEYrRuSgoBE1IUAyma0TGB9HEAr8Azsz3 CFKbLBtM2OpHWjZleKmJ3MnVpTckz8v4/95cXmIT4/S6wE3tkYqctBlOOeCWU1FLMjLH G7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785895176; x=1786499976; h=references:message-id:date:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RsSvF0ThsYwF5rKvJPenXthbv4vP7R634B7PFbVoBfw=; b=D4WCa28hdT4XDSd6cLBAfYJnZ3sXxVoPOsOOFuFZh9F/rgUI9CVYgfloX1wbbLcfAC OBJ0TiJBYEFV8uLsJMDKuO0Df05H5ZkLLrY9ZTqpxvMYh8UsUwMxBgoqgmgJP0wf0fnR Luj9rx8OGF2JAMI6w6J9gpNo9gvXYN70Jp8aHC4GobmpYJBnYHsoW1MMgqeevYw40PKs OfEFZ5zKD2WHryL6QklyE9ZnzYEUA/6JSt7A9dv0AGqLCjTBWfodSGD56uXMmmquZiOY DHnjqnMkHtbomcqTZTDYejrOA4B/bsrBFphjGLSsW9VN89XfLCYKyfcth3SulPKM7MtB y8sw== X-Forwarded-Encrypted: i=1; AHgh+RrsUipgEubIxd0KLYIIgVqMHnzya0rbVvxOvyzqw/t5e/Q2acm1IsorvzpMqn/+92R8NA9ZRGgQ+XqBGCY=@vger.kernel.org X-Gm-Message-State: AOJu0YxkqYdcrLax+yrWmoKS7XIBLGfeDd8VuLz72l9JhN8WzYNA4ilL QRoCJBgx1eNdTSoHIL7o/eJLC3pgpbVL4UCN4IBgHsGRJd+8aV1XlElX9G3/Jw== X-Gm-Gg: AR+sD11/mytAS7IQEB+c30teCaYdYwzmKvUvjQNow4W/MWLX8Qav7o1Tm2exxwQVkS1 0kZptcIuJcvbKLJgumfFk7/sK9D/36L/acL5O7fO4NkLJv5v6o9SNR6vWvxZNj0MzNtFTUFjUEp 8nc2H2o1e86AEVM8Lgyy48LvJAesdfirtu7ge+Dxt3DGhEbBAii3o6mb2MwZRIo6TMuLX4o8HxC pE0H24agtACsMKmZovoGcOyZNe4uIZ2STMSWF5/vFhf4A959enpl8XlEX30o8kfjWRPYhz1PIRW y4544lNdZWPP1qNqUZ2wKMm+wUEfZPUwWlDL0pqruyLWRdv4COfzFYBlDMur4vUa+WF11QvYtMS ud6xwz/v9UvNch1NgpshmZZkJoSKptoIFjE/RzEncslz5Vh18wqLLhx/++35L+1B9TphTLkgbC+ UxoGQaV4qF/i7BktVj956puql63Lt5rjrRZZiuFjlIHJq1boDXzcqioMQgsSA= X-Received: by 2002:a05:6a21:3a48:b0:3b4:61f:1fec with SMTP id adf61e73a8af0-3cb85df12ddmr3853064637.2.1785895175722; Tue, 04 Aug 2026 18:59:35 -0700 (PDT) Received: from pve-server ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3158678ec37sm9511938eec.23.2026.08.04.18.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 18:59:34 -0700 (PDT) From: Ritesh Harjani (IBM) To: Michail Tatas , maddy@linux.ibm.com, mpe@ellerman.id.au, chleroy@kernel.org, atrajeev@linux.ibm.com, npiggin@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/pseries/htmdump: Fix leak in htmdump_init_debugfs In-Reply-To: Date: Wed, 05 Aug 2026 07:24:01 +0530 Message-ID: <1pcdmix2.ritesh.list@gmail.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Michail Tatas writes: > If any allocation fails during init all previous allocations are > leaked and the debugfs directory is left. > Fix by freeing the allocations that have already happened and also > remove the directory that has been created. > > Signed-off-by: Michail Tatas > --- > arch/powerpc/platforms/pseries/htmdump.c | 19 +++++++++++++++---- > 1 file changed, 15 insertions(+), 4 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/htmdump.c b/arch/powerpc/platforms/pseries/htmdump.c > index 489a80e87082..f33941b80ada 100644 > --- a/arch/powerpc/platforms/pseries/htmdump.c > +++ b/arch/powerpc/platforms/pseries/htmdump.c > @@ -527,28 +527,28 @@ static int htmdump_init_debugfs(void) > htm_status_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!htm_status_buf) { > pr_err("Failed to allocate htmstatus buf\n"); > - return -ENOMEM; > + goto htm_status_buf_err; > } > > /* Debugfs interface file to present System Processor Configuration */ > htm_info_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!htm_info_buf) { > pr_err("Failed to allocate htm info buf\n"); > - return -ENOMEM; > + goto htm_info_buf_err; > } > > /* Debugfs interface file to present HTM capabilities */ > htm_caps_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!htm_caps_buf) { > pr_err("Failed to allocate htm caps buf\n"); > - return -ENOMEM; > + goto htm_caps_buf_err; > } > > /* Memory to present HTM system memory configuration */ > htm_mem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!htm_mem_buf) { > pr_err("Failed to allocate htm mem buf\n"); > - return -ENOMEM; > + goto htm_mem_buf_err; > } > > debugfs_create_file("htmstatus", 0400, htmdump_debugfs_dir, htm_status_buf, &htmstatus_fops); > @@ -557,6 +557,17 @@ static int htmdump_init_debugfs(void) > debugfs_create_file("htmsystem_mem", 0400, htmdump_debugfs_dir, htm_mem_buf, &htmsystem_mem_fops); > > return 0; > + > +htm_mem_buf_err: > + kfree(htm_caps_buf); > +htm_caps_buf_err: > + kfree(htm_info_buf); > +htm_info_buf_err: > + kfree(htm_status_buf); > +htm_status_buf_err: > + debugfs_remove_recursive(htmdump_debugfs_dir); > + kfree(htm_buf); > + return -ENOMEM; > } So far the only error this function returns is -ENOMEM, so this looks ok. Later if someone adds a different error return value, then it should introduce a new ret variable and we should return ret from here. But as for this patch - this looks good to me. So please feel free to add: Reviewed-by: Ritesh Harjani (IBM)