From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 A5D1F358372 for ; Fri, 17 Apr 2026 07:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776412537; cv=none; b=BIIU6ccFbSm5WyXQXatJDPmSwx0cc6i40bXtpzPo9JcAeKC3fRIirC7rZ1iQxjBYfb8Q0V6c/KYnwTYI79CIUfpnUozOoOTENsJrp0IGvF5v/5WZuVO4HvGOAZxJhwFnVnZ+bODoBe4ZB8uMfCEE8OahoGWiOMxE0ZvdTJIM9mE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776412537; c=relaxed/simple; bh=qwnO/dPC+6Jc/EcZmne1nxWrHKF3qJsdiX+Yx9rhCrE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M7fzSVuXAtmxQuRV+A7P2u4x8+aWKs9VTjulKgZF4wkdKal//yGZprSec+UtWS8ffIevnDblulf24ypJB3bTSIFj6s2FjwBVe5OslndtLn6vLA7TJOJVfcKN7g94lfHI7DvRRApnXwmjSTSsa5lot+SEHyKcFfrHYooiT38nep8= 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=bv9ISsA4; arc=none smtp.client-ip=209.85.128.50 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="bv9ISsA4" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-488b150559bso3125565e9.1 for ; Fri, 17 Apr 2026 00:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776412533; x=1777017333; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x2gJY7+fGqaHfkh90snhoclQbfvZOKiwtCzkHBs5oMY=; b=bv9ISsA4AFpKgBm1JvXYlLXwV7+Jh5P+BqXsyinO3Qw/ZT16M54SiDfCTBg+eEM83z 3t5kuzbdEVOAh1VED05BTo741tYSQ5au7kv9SVgXsmcl3MvybPtF8Rn98rZaZR96i/LZ NgCZ3p98jtd8TJWFwmE0jTxUDKPyWuUfg8qLllp5owQ7MfCbGAUlkkVs7nvyWCfW4ykS XC0HJeaVfcx7SEtKK7xg7CzjVv0F8asUWQRgfsezR+honZOqsFtKqm6eX8AkPkXoCeXX jOrpubjbyFTz/2MRJEv/gSZoD6Z1v2fukhF8aJmrO5hmQEnjx24Vu+zAr9WD66D1Bl6U HHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776412533; x=1777017333; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x2gJY7+fGqaHfkh90snhoclQbfvZOKiwtCzkHBs5oMY=; b=l8CHoTXjmSVHG7B6HlSKsFksI+1Q+PSAkp99XM/ZZ6m20zzHVWMQaq18SvX4YozjPA x/bQGtE8jW4CE1NSTzNssniAkOHZbVXQQgo1ngpFjzbbueTyDL3Z9bi30I8xqkNQH42e Pklu0cFEHCIiy8cAPAyByvaH3nQ9O60mjeW2P5QqphZhGtqblrNcIz0mZU6UGIFOE2B0 Ncg2UHz7/ikW11bcgnYLhZYQvEXDqN2k7E0W/DJ9684NtzB43Voc8BFZGfI1OgnsnmrC hqm9jn4goJsqAp47HwbfD3RPySOdxvhiQ9VdzsAbum9+WLGGYDV8naQ8f5ZAVwaOyvSK m+5A== X-Forwarded-Encrypted: i=1; AFNElJ+0Q4FveV4/L43FxvOcCkbhXYm9BXC2ytaGHw7jaLI7Ri79btCbCV+t33g0/0SK7OJDJgLuoULuupyFbHM=@vger.kernel.org X-Gm-Message-State: AOJu0Yyctz9+zja8RlEY0GQ1oeI7NsLYyMm18WM3DhYnwnVb2euNO7ZF sJO1X5UceXS/aqbAubyO4yWk37PFRZjQncJtnGO1t/IleALjmqXFdHYn X-Gm-Gg: AeBDiesE3NLMvY3B5VDHkqcC8SZheTIyTAdplOsKATVTb6yljCZl6KMxY+L4HovVzDV HYgC3CsXsJv4YXsFmI0hQsbqptlYvfUBep+TWnbuFLBWQsZPvwMIruZ7UwO9DteFEbD3QRJb1P1 DuX3XAWeqBKdWuMwlrVXMQsh2/HPTt0ouPwYPsa/rJhmlurnsVVmoOZ+YbdPnj2qNpbVGL43CiE 8auC9NaUEGOm2n83efFBDfgkJFHVsgaHpt/cIQBXCyQ+7WuE8nJWqev+/8hOLOLnJ8pdLW+q+RP nSzyqKOMFPvWZBZTIyxUgZyq4ayB/HepKNUMjaJXyoSM6oOk521bh02uoXXdyGLmfihMD9kZuNw OH5vQgnoOnF1yCvxIEXwlmuerUwj4wZViXT9i5CBpJWHAGF4WXhgz4ENMhogSAyg45VCoaGP0xD ANpOK7uCvU5POxjkwYguPDGLHXpmcIsA== X-Received: by 2002:a05:600c:a30a:b0:488:8d44:bf98 with SMTP id 5b1f17b1804b1-488fb74a5f3mr18115405e9.7.1776412533399; Fri, 17 Apr 2026 00:55:33 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fc177dafsm30313095e9.4.2026.04.17.00.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 00:55:32 -0700 (PDT) Date: Fri, 17 Apr 2026 10:55:29 +0300 From: Dan Carpenter To: Huihui Huang Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Sakari Ailus , Greg Kroah-Hartman , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] staging: media: atomisp: fix memory leak of dvs2_coeff Message-ID: References: <20260417070124.2677399-1-hhhuang@smu.edu.sg> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260417070124.2677399-1-hhhuang@smu.edu.sg> On Fri, Apr 17, 2026 at 03:01:24PM +0800, Huihui Huang wrote: > There is a memory leak in > drivers/staging/media/atomisp/pci/atomisp_compat_css20.c. > > In atomisp_alloc_dis_coef_buf(), dvs2_coeff is allocated by > ia_css_dvs2_coefficients_allocate() and stored in > asd->params.css_param.dvs2_coeff. If the subsequent > ia_css_dvs2_statistics_allocate() for dvs_stat fails, the function > returns -ENOMEM without freeing the previously allocated dvs2_coeff. > > Add the missing ia_css_dvs2_coefficients_free() call before returning > on the error path. > > Signed-off-by: Huihui Huang > --- > v3: Remove unnecessary NULL assignment per review feedback. > v2: Reword commit message per review feedback (no code change). > --- > drivers/staging/media/atomisp/pci/atomisp_compat_css20.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c > index be5f37f4a6fd..d6e135c42e2f 100644 > --- a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c > +++ b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c > @@ -1363,8 +1363,10 @@ int atomisp_alloc_dis_coef_buf(struct atomisp_sub_device *asd) > /* DIS projections. */ > asd->params.dis_proj_data_valid = false; > asd->params.dvs_stat = ia_css_dvs2_statistics_allocate(dvs_grid); > - if (!asd->params.dvs_stat) > + if (!asd->params.dvs_stat) { > + ia_css_dvs2_coefficients_free(asd->params.css_param.dvs2_coeff); > return -ENOMEM; > + } The design of this code is that if we have an -ENOMEM here the caller, atomisp_update_grid_info(), calls atomisp_css_free_stat_buffers() which calls ia_css_dvs2_coefficients_free(). I can't tell if adding a second ia_css_dvs2_coefficients_free() here leads to a double free. I call this style of error handling One Magical Cleanup Function. It's always buggy... https://staticthinking.wordpress.com/2025/03/31/reviewing-magical-cleanup-functions/ regards, dan carpenter