From nobody Wed Oct 8 06:47:12 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 3BEF32309B0; Tue, 1 Jul 2025 09:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751362871; cv=none; b=GDbnO3HSa4PaMghVsn87B/qpDcSC8n1rH9aW2pQ5ZxvZUl3kX4B8/MHJRBIC9NFJRaAkG5LPXdUIu0wDAScE/47Hok/5ltgJR8yBI+EFfPRU9nHEyuMet6ViXHky2sOC/E89HsR3hPse3CWCMQcqEuTdG5ExyS7yVFmVWFUiHm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751362871; c=relaxed/simple; bh=5kQ5HbATbSWIj1JFpHo9PbQOlrrjpSHqiXePkD1/QwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZmY5sVCLRz28Y0mmHMr6kawd0nQbWwJ34OqbXaXpKj7KGW0uk5xyYIWpwHFnHcxedNDeOB715Kb+FNY6YR5h3KiNItpP9JYq/cA7RmDBksxiAQjbM5Vc98x6NysB4UctPOFiPRB6/BB7lH+e09oMuzWwbBcKttpOdWasRIDgbBk= 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=H6L/tPkV; arc=none smtp.client-ip=209.85.210.171 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="H6L/tPkV" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-748fe69a7baso5327761b3a.3; Tue, 01 Jul 2025 02:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751362869; x=1751967669; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p6VPondI9s6Ps40JI4paXgB0FQE9DZBVRKYHGloiqBo=; b=H6L/tPkVawvlIDEEwtTykVMbtWXej8RN++CeDoxO2Ch9EoJmv1yFjkuBx7mtV/hO9W 484Sj83750T6+RFaX25Ana1Crq9dBi+RVQKe6s/6rCHSV3YBNC9sUctxdd91AVdEHuEf JT1HM5hrx1aL4nHkIjLF+85dYUp+2MPRG5UT0B5UZXCnJ5qS0Y+gye91EZLKsT4uC7+a q/lTuD1E+gcLFRNqAfmnH2nz2gO/FDcoUwXNN4bAfMeUE5ozWALaloHUk3V1kHnfZaE+ tJ8qBCCe1WEOcLW/1VxdCBsNOrtGtWsWrhiN0XNSYwPrkm47cPmUcKmK5FNzpdNVqGr8 s1Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751362869; x=1751967669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p6VPondI9s6Ps40JI4paXgB0FQE9DZBVRKYHGloiqBo=; b=XTP9/1oClFo4oZ2RumGpetjqCUEoEaSlxS1Kk55ISV0rN6+x9aRgI/w0lyhaCxtTFJ p/fneHsMaFt+qxD5MoR++rZyZB4viw+v1lEHUYcVK0a1RnjTfK1MMMaDz+0lhR+mJ5/Q oXkaWxAnWN4gGmYmXi76fkgCLgNuTVVbNyshyxzJ2oz0TQWw27xJzNvCkyWelkoFMmHp 6Lzhk52UIWBZvcFDiWg9InfVxPeybfEz6DLpWapbjHMV19g7vPGeSMGkjpDRJ2NZZxol nZiIgLZaF0WmS2hMXOTswcPZj1bf7gvcpF7TZD1/YRckdCV0iJlMGcgDIi58a/j5TN6B /ZrQ== X-Forwarded-Encrypted: i=1; AJvYcCUIMedv+URPeaL9/bsTfCamLTcKe60WRokGsXxzZbWX0m7PBHFi8W6D9elyQugSEad0E9cSimFNxJ4vJw==@vger.kernel.org, AJvYcCWgJqJqzn8rX685cYQKWrQoxZe3+8HwqaNXCCY1/IvimWMiXXcBB1MUop7v+VrV2Ucatl7opYwwdidZfPk1@vger.kernel.org X-Gm-Message-State: AOJu0YyBDOPcsF/M5qxnqpvG35ErdPQAD+RnflCUpvr8yuQg+6F65tvp 5xgmS4ZBaaYo21lx7Z8ujD5+UjCJnM+VBoZiKZTTw1FUKZa+fupm+Aav X-Gm-Gg: ASbGncvIFLTyT25YlzVPwuMcRZoE4vIRShahP2PdaHDTpacOJtLYsh/5iqXHvyrKOaN U4jjzFweDMzs78Mp+23J2LlZwDJ/dDjPMG1Q+OokGy8lZGHUSONV1Lfxrj2weS9m5i2xKWf1GiW upGUWxILGSUUlL5QkVuowoKnssjiQvwmzya9C/4TdCNtbvGjI9eGAKTtdOHJRrBSO5x+7P83rwK +kDCdCupbfnmCdzBP5pjqjOiOpUO6ee63Ukjh0xW1q+ctV7jOrAHJ8F5eZbKy52MaaTaPet959G M0HInSRYf/IQhxaNWwr5y+wkgJatF6ML1WWurw03JAnwCCPhoQqeoA3uLMsKL/llzL/Im5pl7BF jIw== X-Google-Smtp-Source: AGHT+IGCUJ6tlUrEWS8XsccIwNxw4AUXaAE5LiMgz6vheF+DRB+JBGiWDglKUzh32UvkY9tpeCODvQ== X-Received: by 2002:a05:6a00:1302:b0:736:43d6:f008 with SMTP id d2e1a72fcca58-74af6f40a01mr24461769b3a.12.1751362869457; Tue, 01 Jul 2025 02:41:09 -0700 (PDT) Received: from localhost.localdomain ([49.37.221.186]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-74af57e7279sm10945766b3a.150.2025.07.01.02.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 02:41:08 -0700 (PDT) From: Abdun Nihaal To: andy@kernel.org Cc: Abdun Nihaal , dan.carpenter@linaro.org, gregkh@linuxfoundation.org, lorenzo.stoakes@oracle.com, tzimmermann@suse.de, riyandhiman14@gmail.com, willy@infradead.org, notro@tronnes.org, thomas.petazzoni@free-electrons.com, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] Revert "staging: fbtft: fix potential memory leak in fbtft_framebuffer_alloc()" Date: Tue, 1 Jul 2025 15:10:22 +0530 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit eb2cb7dab60f ("staging: fbtft: fix potential memory leak in fbtft_framebuffer_alloc()"). An updated patch has been added as commit 505bffe21233 ("staging: fbtft: fix potential memory leak in fbtft_framebuffer_alloc()"), and so reverting the old patch. Signed-off-by: Abdun Nihaal --- Newly added in v4. drivers/staging/fbtft/fbtft-core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbt= ft-core.c index d920164e7710..8538b6bab6a5 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -695,7 +695,6 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_di= splay *display, cleanup_deferred: fb_deferred_io_cleanup(info); release_framebuf: - fb_deferred_io_cleanup(info); framebuffer_release(info); =20 alloc_fail: --=20 2.43.0 From nobody Wed Oct 8 06:47:12 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.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 BCD262309B0; Tue, 1 Jul 2025 09:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751362883; cv=none; b=QQ3z+24bki9RsZQvcKxtfSURrSgfl3QLRQrlzYGSSYlxv1LJpHSO6FlOp2SYrinqXOVEC7+Fy8WdcP0PJK3JlNTZpnYDXfmZIRFF0qAhpzbLW3InrOjCgLnFMZ9dQm5SfWqztIFc1g0jjUlptY+3yuwFFvXrDxIp4fCmW28AXLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751362883; c=relaxed/simple; bh=FaxaoUeulagyOhU2b4Z3SKWcM6w9W2nx/IlkDhnCqXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aF9yhY3NxNV12fYVZG3VIZrtkVJKCunrhWAL/cfv0Owr3CgWCiSDt9TRbCy7sMU4unKAnQVK/uhd68QWS/ClFGub8jB+pNRR21IIECkQ+KRWnN3G/YvlsrghuYuqB5Oo1iIwR3LazaqNc0CCmBWXpSKXPuCVkMAbGDNGqs0okdA= 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=EyqWam4P; arc=none smtp.client-ip=209.85.210.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="EyqWam4P" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7490acf57b9so2279426b3a.2; Tue, 01 Jul 2025 02:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751362881; x=1751967681; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3PnEDkQYSGlej4tjD/bQ1dPRo4xaWxnAEWg0UHJoseU=; b=EyqWam4PmJTsgcD7uo1zm3vcfmjuKwoZZn/XgqVfcjcyLT5A1QDKyKc7kKdbDCP0Z3 9zrxXaurgyjSjusf+PWrFg6K+6UIIMFWzsbs/Xmwv+R498Y4CGARfZruHmhtghINCUQp l0plSjUWNMsQ2erjrVKd6Eak0QJ8zRYxA+UBxerwdtdu/snTkHbwHO+jadZnteNF4NK4 FuzZPmVhtYWpnyRVx8Sll6lavWzAoP33jhI7fIzKcFEmKnCZ5b2iAyo6+S9D4UlZIYgQ Lj65lbX5vgtonHPL1RRPGQ6B8KqXQDwyIMMIi1aMblVqkCBNcAkmJWM9ARC2G1Kxg5i9 5vIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751362881; x=1751967681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3PnEDkQYSGlej4tjD/bQ1dPRo4xaWxnAEWg0UHJoseU=; b=QUu0leV47GZo888cpsD1MqdFJzTWyA6F9Uzt9YZ4H9duOR8h25FgGylFsWdmFLMy1S nmLdim9fhh6+yEoDb88LgU6sVBK/PktnKGAKnzx5FerwSijZJWJnLwRS00RHz6thLhjj ikHM97pxdspl1FADB8DnM89SorSNejIzskeORAGW8+u13MtuVIsS2OhJdBTQmC2hBBY4 9BrC6DGqwoX5NWaA0Fq3LdrzJPRmqYjcJFiF/DRJ5oUT6Ir+mLQ99w1gli3ugzrv0ZV/ 2ubEUqRsfd33Qz0rVI9XhFSMUkr11y6fnPLL165YysjMjRrrzJAZYIcoGHXnhbbMHaBY 0NMg== X-Forwarded-Encrypted: i=1; AJvYcCWuaV6RsiD4OyUbpbbsTyINV5Ffx56csRR4DwAQegDOmg9ApbXEqXMriezrwQPa9av3SV9BmY+GD8vLZA==@vger.kernel.org, AJvYcCXKRDj3KPIVJrNEMjE9ZXCRIQLUxj1aFoTzQHjc5z4XS4WJQ2qi42Rk1IB+tdfNhBRfJgxosoGrgTyVMH9+@vger.kernel.org X-Gm-Message-State: AOJu0YwM2frZCp2lBTENOJJxIGoHDFNuABespRiuQeU3SYcOGu6iOQzT gIsAamF8f7+4PHeSxnfVlBI7AqXC+WqHptHseFDAvYWO1qG2eji2+8ZD X-Gm-Gg: ASbGncsVSwDiiSK8+pWjALfavG8+yvoDdVEows5isimSbUp8XB19UJW2694RTQd6sTI NSXDyjQ6T9DkO+vjY4jWaYz9HRHgb8cwBFRBj3ttKycLlCJrbD1hHHk2nFw/CQmIBWrhqnGUAxM 8UqLVCrV20GBll1zfLhvEZjGa7D7vFFAE7u3DASO3eatzb6lDAfjWZtQx2Io/B4uz7P+CQnytNl RySiAoypkA36GSrejwuad4XmllahnI0WNN/qbDN+6kYGQbtaHxbD3I2grDPzIRDzeWoGkI6wc/C E5Ffou+FQIvlMnXWw0O45cccl328uYBjxvpm+r9IhQYIUTuhlLMXC3PeUNUrcnKjeMRaU14p5wg Qgw== X-Google-Smtp-Source: AGHT+IEbeQc69MS0gQNp4/0czRTMPM7cTE3egdA7+5pA0TfD6EU6FUYVk5lBMVTPZAs3gk2+USbR3A== X-Received: by 2002:a05:6a00:2302:b0:748:1bac:ad5f with SMTP id d2e1a72fcca58-74af6f22722mr22370210b3a.12.1751362880881; Tue, 01 Jul 2025 02:41:20 -0700 (PDT) Received: from localhost.localdomain ([49.37.221.186]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-74af57e7279sm10945766b3a.150.2025.07.01.02.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 02:41:20 -0700 (PDT) From: Abdun Nihaal To: andy@kernel.org Cc: Abdun Nihaal , dan.carpenter@linaro.org, gregkh@linuxfoundation.org, lorenzo.stoakes@oracle.com, tzimmermann@suse.de, riyandhiman14@gmail.com, willy@infradead.org, notro@tronnes.org, thomas.petazzoni@free-electrons.com, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Andy Shevchenko , Andy Shevchenko Subject: [PATCH v4 2/2] staging: fbtft: cleanup error handling in fbtft_framebuffer_alloc() Date: Tue, 1 Jul 2025 15:10:23 +0530 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The error handling in fbtft_framebuffer_alloc() mixes managed allocation and plain allocation, and performs error handling in an order different from the order in fbtft_framebuffer_release(). Fix them by moving vmem allocation closer to where it is used, and using plain kzalloc() for txbuf allocation. Suggested-by: Andy Shevchenko Suggested-by: Dan Carpenter Signed-off-by: Abdun Nihaal Reviewed-by: Andy Shevchenko Reviewed-by: Dan Carpenter --- v3->v4: - Added Reviewed-by tags v2->v3:=20 - Remove the if check before kfree of txbuf.buf, because it is zero initialized on allocation, and kfree is NULL aware. Newly added in v2 drivers/staging/fbtft/fbtft-core.c | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbt= ft-core.c index 8538b6bab6a5..9e7b84071174 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -568,18 +568,13 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_= display *display, height =3D display->height; } =20 - vmem_size =3D display->width * display->height * bpp / 8; - vmem =3D vzalloc(vmem_size); - if (!vmem) - goto alloc_fail; - fbdefio =3D devm_kzalloc(dev, sizeof(struct fb_deferred_io), GFP_KERNEL); if (!fbdefio) - goto alloc_fail; + return NULL; =20 buf =3D devm_kzalloc(dev, 128, GFP_KERNEL); if (!buf) - goto alloc_fail; + return NULL; =20 if (display->gamma_num && display->gamma_len) { gamma_curves =3D devm_kcalloc(dev, @@ -588,12 +583,17 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_= display *display, sizeof(gamma_curves[0]), GFP_KERNEL); if (!gamma_curves) - goto alloc_fail; + return NULL; } =20 info =3D framebuffer_alloc(sizeof(struct fbtft_par), dev); if (!info) - goto alloc_fail; + return NULL; + + vmem_size =3D display->width * display->height * bpp / 8; + vmem =3D vzalloc(vmem_size); + if (!vmem) + goto release_framebuf; =20 info->screen_buffer =3D vmem; info->fbops =3D &fbtft_ops; @@ -613,7 +613,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_di= splay *display, info->fix.accel =3D FB_ACCEL_NONE; info->fix.smem_len =3D vmem_size; if (fb_deferred_io_init(info)) - goto release_framebuf; + goto release_screen_buffer; =20 info->var.rotate =3D pdata->rotate; info->var.xres =3D width; @@ -668,7 +668,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_di= splay *display, #endif =20 if (txbuflen > 0) { - txbuf =3D devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL); + txbuf =3D kzalloc(txbuflen, GFP_KERNEL); if (!txbuf) goto cleanup_deferred; par->txbuf.buf =3D txbuf; @@ -694,12 +694,10 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_= display *display, =20 cleanup_deferred: fb_deferred_io_cleanup(info); +release_screen_buffer: + vfree(info->screen_buffer); release_framebuf: framebuffer_release(info); - -alloc_fail: - vfree(vmem); - return NULL; } EXPORT_SYMBOL(fbtft_framebuffer_alloc); @@ -712,6 +710,9 @@ EXPORT_SYMBOL(fbtft_framebuffer_alloc); */ void fbtft_framebuffer_release(struct fb_info *info) { + struct fbtft_par *par =3D info->par; + + kfree(par->txbuf.buf); fb_deferred_io_cleanup(info); vfree(info->screen_buffer); framebuffer_release(info); --=20 2.43.0