From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BC79205AA1 for ; Mon, 16 Dec 2024 14:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734358035; cv=none; b=ld5bDLn9xt2EkrSCe8WX79+xuQ0HmohGdb8FEp2VDDC5Ou96HQAMoGT5x+W6ZPdK9bdOHs337TDDQz8rArfgPbiGMkYLJnRpd84RSfUWkQ+ir9bDe9jw+RY3A0Z9O9wneR+7E9h5k40Dtszx7l+CUo+OeeURsyUIyVHx1a6rkBk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734358035; c=relaxed/simple; bh=R0r6kyXtqnw9oAO0kUc+2aV4wsHJJzh2fmz7yt1ZKQE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DiG0m7RI745bvy78Cy+qEwssXIdPvRZYnzeAf+mAwFVowEMSGEh4R6Tgf6mGolqcWAtln0KDKKapkj1zI1Elm6OAPLxYcZc7N89Y1FklS68h1PZ8c3T2AebsfCtnhEn82TC2tQwX1ZbiYnlZQ9LoKHeA2eTxGYcnv3or3fZA79M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bfnpS8kf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bfnpS8kf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734358032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Vx9u29TJnDx+NQoG8CYOpQFQkYPuT5i21NbIJ3rQxpI=; b=bfnpS8kfi5ykgZAlfo5rPgxRphMY/dMO7o3tPF0+szbtViFeNsRmSa9badb47uzHJ4Vgiw gVd9BeQeJb7Mhzfj0YpKDifbVXr/HSMQDsX5UpXvzTD4HTo9mL3PxnVH+XUXg8f2WjNug2 4fWuS/66cEJTNV4R1a/PSBPF17uTUVo= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-oZvVxXzGNp6bG1HDVXhQCQ-1; Mon, 16 Dec 2024 09:07:11 -0500 X-MC-Unique: oZvVxXzGNp6bG1HDVXhQCQ-1 X-Mimecast-MFC-AGG-ID: oZvVxXzGNp6bG1HDVXhQCQ Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385fdff9db5so1158661f8f.0 for ; Mon, 16 Dec 2024 06:07:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734358030; x=1734962830; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Vx9u29TJnDx+NQoG8CYOpQFQkYPuT5i21NbIJ3rQxpI=; b=pWBrd05nleipo7pJetrk188gPeGKk9quY5iiE2wJTpaZzJJSU5XqYnFL0fqHw2ctwE dv2JS3NLZ31of1JtRURi/7ZocynfgbCEtA1R6fMl46kCo/vECtiMoR8F2j2nZsKOwf3i IyUDXJ6AlH3AlSykAPK1SdNapV73yIHRoGIcblMKkJhPZx36WpS5UwBZySOYIIkpSSs1 nQ5riQ/sOUdtm+Zq1H2tMENQ3E7jl4HEJE2d7o7wMXy8V670/aQT05kSqsneG/zWzyaB /PksBlKM2GaWws/mgvdTzWguzMagySJ1SgZJFA5hZqk0Czj2WJRnPfY+zkvDOsq3FH4N f8Mg== X-Forwarded-Encrypted: i=1; AJvYcCUO720dagfvoHRtmNHAhe86yhWDz02ki1i5oUYdJRMbU8KrMEtQcophrjK/OlfTNqLQwQmEo8YDOA1viDI=@vger.kernel.org X-Gm-Message-State: AOJu0YxJY7G5f7BS5ozTB/WUPeBxkwqqF8aab4tDmq6MVs8Ve/olTWyn x4NZ1Vookpwu5Z2t7U+atKey7J7+WQVPJwoNuBTxWo6s11GPpeM17/OwLILxQx/KxoxCNhj7n7g x74Cr2Tw3t5icAZcgP9UM2enmbPEJ8NqlQ+1+U9c0zRK6m+J3rg/kIJMcUx76lA== X-Gm-Gg: ASbGncsI8e2nkhpg+F3G1RYHKJk4Cq16aJzJdKgG6U3S9xA4z+EHYlkcJIAxK1mCT/C d8B3Vw6bEejvzB2WPEWEzfyAGk4rbrCxNYwg/rNQ8pklWA26tO+Liy3vA1v90xalCRmGnsM7VAm 6hGeIfJA9GkCQygBNzXQoZhiRDXSkZ6QmolttzRdYmmczIq1e/SNKGRotGKKJHpluREr7cvKhW8 h30WzDmvaA1clWaXqR8twfhXiAoagEbJ9sFnrpHYngMjC6bqh84 X-Received: by 2002:a05:6000:400b:b0:385:f398:3e2 with SMTP id ffacd0b85a97d-3888e0b8ac2mr10303692f8f.37.1734358029442; Mon, 16 Dec 2024 06:07:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyZ0+O4kIxKWHQmAwP9mPVHk0LghHzqDQ6QyhAYSUm6qYdEdlC5E3x4M+gkrrJ6yoDU0YReQ== X-Received: by 2002:a05:6000:400b:b0:385:f398:3e2 with SMTP id ffacd0b85a97d-3888e0b8ac2mr10303638f8f.37.1734358028978; Mon, 16 Dec 2024 06:07:08 -0800 (PST) Received: from cassiopeiae ([2a00:79c0:644:6900:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c80613a9sm8199671f8f.101.2024.12.16.06.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 06:07:08 -0800 (PST) Date: Mon, 16 Dec 2024 15:07:06 +0100 From: Danilo Krummrich To: Zhanxin Qi Cc: kherbst@redhat.com, lyude@redhat.com, airlied@gmail.com, simona@ffwll.ch, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Duanjun Li Subject: Re: [PATCH v1 v1] drm/nouveau: Fix memory leak in nvbios_iccsense_parse Message-ID: References: <20241216130303.246223-1-zhanxin@nfschina.com> 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: <20241216130303.246223-1-zhanxin@nfschina.com> The version after the inital one should be "v2". You can use git format-patch -v{VERSION_NUMBER} for this. On Mon, Dec 16, 2024 at 09:03:03PM +0800, Zhanxin Qi wrote: > The nvbios_iccsense_parse function allocates memory for sensor data > but fails to free it when the function exits, leading to a memory > leak. Add proper cleanup to free the allocated memory. > > Fixes: 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") This should be Fixes: b71c0892631a ("drm/nouveau/iccsense: implement for ina209, ina219 and ina3221") instead. The function introduced by 39b7e6e547ff ("drm/nouveau/nvbios/iccsense: add parsing of the SENSE table") is correct, but the other commit did not clean up after using it. > > Cc: stable@vger.kernel.org > Signed-off-by: Zhanxin Qi > Signed-off-by: Duanjun Li Why is there also Duanjun's SOB? If there is a co-author, this should be indicated with a "Co-developed-by" tag. Adding the SOB only is not sufficient, please see [1]. > Signed-off-by: Danilo Krummrich Please don't add my SOB to your commits -- I'll add it when I apply the patch. Please also see [1]. [1] https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin > --- > .../include/nvkm/subdev/bios/iccsense.h | 2 ++ > .../drm/nouveau/nvkm/subdev/bios/iccsense.c | 20 +++++++++++++++++++ > .../drm/nouveau/nvkm/subdev/iccsense/base.c | 3 +++ > 3 files changed, 25 insertions(+) > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > index 4c108fd2c805..8bfc28c3f7a7 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/iccsense.h > @@ -20,4 +20,6 @@ struct nvbios_iccsense { > }; > > int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *); > + > +void nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense); > #endif > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > index dea444d48f94..38fcc91ffea6 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c > @@ -56,6 +56,19 @@ nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, > return 0; > } > > +/** > + * nvbios_iccsense_parse - Parse ICCSENSE table from VBIOS > + * @bios: VBIOS base pointer > + * @iccsense: ICCSENSE table structure to fill > + * > + * Parses the ICCSENSE table from VBIOS and fills the provided structure. > + * The caller must invoke nvbios_iccsense_cleanup() after successful parsing > + * to free the allocated rail resources. > + * > + * Returns: > + * 0 - Success > + * -ENODEV - Table not found > + */ Looks good, thanks for adding this! > int > nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) > { > @@ -127,3 +140,10 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense) > > return 0; > } > + > +void > +nvbios_iccsense_cleanup(struct nvbios_iccsense *iccsense) > +{ > + kfree(iccsense->rail); > + iccsense->rail = NULL; > +} > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > index 8f0ccd3664eb..4c1759ecce38 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c > @@ -291,6 +291,9 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev) > list_add_tail(&rail->head, &iccsense->rails); > } > } > + > + nvbios_iccsense_cleanup(&stbl); > + > return 0; > } > > -- > 2.30.2 >