Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3344589pxv; Sun, 4 Jul 2021 16:07:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOS3bRWGgjEXtm0VwTtx4fjVDhnqVJL0DcKQEYIpK2eXbHoAMYE3tOhFVMsCo41GYJmeaU X-Received: by 2002:a92:c747:: with SMTP id y7mr7848174ilp.199.1625440056355; Sun, 04 Jul 2021 16:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440056; cv=none; d=google.com; s=arc-20160816; b=Hlu+Uy5bdYOc5AsxPY8QMMlMIbVA1u47kTzlX6mMHsXCPozssjQa/yirEKqGU+A9GC 7MKazfzPpAfp+whienDSwJQ31lgOxRANczYrf1xZFhDPJ3DbS99klcrHWCwqnf7DCvTU MO+aad+Tjt98iYiO8ogHEjLiATfVZPWlpWUE45Q6J4fYNNZqZX1+THk2XdvovS+C4hB+ XLnKkLYI6V84ZS+MELVmyBy1zjtXreXc1lO0uavnmC39IqU4ytKF1X9hROK+wtpMHqSH 4wlWu9y+fb6a/H+/a1srBwuDbINUiYq/VbQkbY21vrPiQr7yx5/KgSinAlpkMmkMSq/5 gqKw== 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=PuaFHq5TKiXCKH2zIiXIJzbOsISkDJjXg+H+qKCmiRKWXUyOs9sTb1c0my0rlHT+0A PbIwJQybE2HV0I0NRlm23M9uD+1ObdlP7SL22fr51eWltJaCAlV85HIS1Cv4Jgn8zdWu KHwkA/jJ7wwwWmMDQUZU+5q0J+bq4TUudZ/d77rpYUKghSCkxAamQft09xB8CK6nzH0/ sPZFAICSiwZhdk7DCBn7DWxw7yXfHED0w13SmGri+XezQlVCzADNl/o1qvIwtQ04xmFY LOgnv11SWJxaSh/n51oEC2PUJk/HQoOuDnQ+euFZq41RaIysJ/HBQfnX2al7eFjouCOo eh0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IBg6+SRe; 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 p31si13218190jac.95.2021.07.04.16.07.25; Sun, 04 Jul 2021 16:07:36 -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=IBg6+SRe; 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 S231376AbhGDXIi (ORCPT + 99 others); Sun, 4 Jul 2021 19:08:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:46478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbhGDXHx (ORCPT ); Sun, 4 Jul 2021 19:07:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AEB63613FC; Sun, 4 Jul 2021 23:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439917; bh=H6I1CzE8LzvNbpcekBj5LRlqnEHe8h7OLwJsoz0QF8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IBg6+SReLSUjMc9tyNf9OWqnwD/hNatQ726up4E1jWJI+ZFmqym9A1Xs37TF9TYaD LFJJ2Wjpa7Qc3T6PGQ9AfcJq/TE4EZzyUWI+hp/DhRANLnrZ4ShKq1fa9/fI/jmv5S v0/xCyAQQj/tcJz3NPUPgnuOB+tDbdLbTWcirBi12Y0RR8al7uwJGCWYp6qOvhy8iT feWGLWHMFPFIm6Wyhkxtp2y3AhkaGeSjX48UjO6LVcBNfHjj/79f8BLnzn/uhAu8bF ZadbA3hBSx7Lbp3szjVGTRXOfyVyv9bvq3fGkQoQBQ5E2af3joGXYVAwpDO+pfWrsn PC1/nLwqs7Tzg== 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.13 41/85] media: em28xx: Fix possible memory leak of em28xx struct Date: Sun, 4 Jul 2021 19:03:36 -0400 Message-Id: <20210704230420.1488358-41-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-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