Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3346410pxv; Sun, 4 Jul 2021 16:11:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTjZaqeDx3ck1tyHsEJbHwWUWdGTxjKdCkUKtOvlQp6cO8aePZfVwOTDOeNLCpG+xDfKOs X-Received: by 2002:a6b:d115:: with SMTP id l21mr9578992iob.130.1625440262846; Sun, 04 Jul 2021 16:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440262; cv=none; d=google.com; s=arc-20160816; b=lkMugBaYlZ9eGkEvLKS+kZDkX4g0S9m/l8pjkrVrXBD//f9J5hAqwcdWREqlZyLpEE jxKrJpTPFhZE7LrupjLyckA+D/heLPDLMPrmk4ejq55Pyp4DgKjvVt421Lw+JH5mVPDL 59YL7pKsk4OH1T/jnykuM6g2pMwsqqXjcZ0bVke7ptXs6QCSz9SG6AfoJepl2FvcnlpV SPd8yVlCO41UEQ/+vO4rCVwzUuFkYaWvicoFt7qzF3MCknXGbUMTrfYDRtICoCONCKIv NxNCNVcrYn+tVf/GGqa/bYIOYSRLeRF/C9EcmNLcT+U+c69fb4w+n+QTauh+zLRwpQbz 6SNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VjPG43dH1z/NjX4xpgpHPkTqNILFdO5NexszVjHmq5A=; b=JC0HJMb04MmRQkAW0VdVAQj4FNrHKT1NZs5dGAvjE0ZgLOGUCLVKAZFl4ej/0xrG9D BHTXQ9uiOdfn5NN1zI9PZH1WLgFki/up5HNGu1UgHV/IO+6Ef/X/JipYuLqXgAI4lIHe hHoQo5zrLuJoBWv3I6CxkGSASEWiIRnQyCvAPVl/pkiDnkrXpDfcu+ilFo9/M/twGxGJ 2DzL/mxRH76zPnSgOMsW3YdS9Vujv+SauW+3EAZF1ig4axXiCAkcLE4ZjiXwTWUeaCDu Q0yrhFmxGlxHxwV68/XIqupd5ulFjFCzabjfFPLQIWqvnxYFchnnHww2OQ1tssRimGZa ZbXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SzlGqzDR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l19si12003667jak.112.2021.07.04.16.10.50; Sun, 04 Jul 2021 16:11:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SzlGqzDR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232306AbhGDXMu (ORCPT + 99 others); Sun, 4 Jul 2021 19:12:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:49128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbhGDXJ6 (ORCPT ); Sun, 4 Jul 2021 19:09:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BCF9A611ED; Sun, 4 Jul 2021 23:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440030; bh=H6I1CzE8LzvNbpcekBj5LRlqnEHe8h7OLwJsoz0QF8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SzlGqzDRF+CopfYl/smHCAJZJBe7m2WEoFE9NWZgqmeNI883t1LfU6mwRk9/WoyJi SMQgu2+QhTGLhVBO38zWxpj92V3Mfa5GX2xXmcEHdeCVLwoBppigAiGGZppPgm7zdj kG9tuBvCzGqZ35p2ZkdkY5t3TYS7ZPQuLYSrItj3E7oIaO+8fhUmCZFIl6p1z2W6mq JFWNnSvUeVwZSKfWzUZ5yev9ryOa8sujTetJONFZN48z22QHhAcSaW4yI1febwcNn/ fMfNh+celmB3L6YpJUqE+EEwubIu4XC6FQ51p+xqKGQK4fohbIJjohI/Uyc+3OfECa Xwlu/RgOscaCA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Igor Matheus Andrade Torrente , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 39/80] media: em28xx: Fix possible memory leak of em28xx struct Date: Sun, 4 Jul 2021 19:05:35 -0400 Message-Id: <20210704230616.1489200-39-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org> References: <20210704230616.1489200-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Igor Matheus Andrade Torrente [ Upstream commit ac5688637144644f06ed1f3c6d4dd8bb7db96020 ] The em28xx struct kref isn't being decreased after an error in the em28xx_ir_init, leading to a possible memory leak. A kref_put and em28xx_shutdown_buttons is added to the error handler code. Signed-off-by: Igor Matheus Andrade Torrente Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/em28xx/em28xx-input.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index 5aa15a7a49de..59529cbf9cd0 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c @@ -720,7 +720,8 @@ static int em28xx_ir_init(struct em28xx *dev) dev->board.has_ir_i2c = 0; dev_warn(&dev->intf->dev, "No i2c IR remote control device found.\n"); - return -ENODEV; + err = -ENODEV; + goto ref_put; } } @@ -735,7 +736,7 @@ static int em28xx_ir_init(struct em28xx *dev) ir = kzalloc(sizeof(*ir), GFP_KERNEL); if (!ir) - return -ENOMEM; + goto ref_put; rc = rc_allocate_device(RC_DRIVER_SCANCODE); if (!rc) goto error; @@ -839,6 +840,9 @@ static int em28xx_ir_init(struct em28xx *dev) dev->ir = NULL; rc_free_device(rc); kfree(ir); +ref_put: + em28xx_shutdown_buttons(dev); + kref_put(&dev->ref, em28xx_free_device); return err; } -- 2.30.2