Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1838724pxb; Mon, 13 Sep 2021 06:40:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhomzrdk/qOOzEaUfkb59M7a05LgOVNgNFqPplpVVk+hxz4BnaCSFW6S+HeDil+0njQ9Cq X-Received: by 2002:a92:194c:: with SMTP id e12mr8330895ilm.3.1631540427818; Mon, 13 Sep 2021 06:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631540427; cv=none; d=google.com; s=arc-20160816; b=jdElLDxPfbPaFUMiFk0b8dgRWi8Ga7DmG/i4wnewqx3c9qQYFgS9hKSbNZBC4YKN6y UPRptk7bfrcLnZm+d5Fo+KhuJrZwa/OsQqO2ec4pZ4rhHq68qX36W2FXQTJIthUCxXSq n//zBApyp36/TxbYdsUTx7dZoo4MIg+Zdz7mheTOKp1iuwwVXXRbwHnYTYqtF6gnEfb6 pSKTiu4haZJy1bShCh3TL8hQYATmayt8pkI8ARhQS9TLBd00uUmJLzsJhzG2yUOJ2QUo kPYMV+qosCRh3OueUsf6FyzlymMfXDCTsHfJBXa8x3v9Ig0/r9i9KjAKt7GLD1yZ4AEA RglQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VlKemIVMOt3kEoVCWy5d+sHOzDk5m9AEY92cQ5K/ZZs=; b=HUPVBEGRuEtVIGmk3r+FWJAn0ntBEwZLclbeg9F9uG4ASkj1ZLQzQ5uhzgyDsG1V+t JCDCgpm0/F5qP05oBKE8ECBvaLAMo7H6JuHBGokPPYtyaT5ktdRCuMLPuMfJpINjQ7vA wDmaDkmQpGEGeBK07h/hfme8z7RErctobnq35rBajqsC0zg8get12Wjzwn7eCpmGRp/I GMYhVOV7dgh/NkG/IS4eKm6OkDiN0TgMUleEt+MG79TVUq6e0Ixt6G3Q5eIInW9OK9eX ZzPEv3BasD5LfxtkYX/neCv1A6Gzoj1VZV4jppEUbf1w/7E/zeTsjOr6kwRcHdvtY3i5 9dlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JUOTD3Qo; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si6407131jaa.5.2021.09.13.06.40.14; Mon, 13 Sep 2021 06:40:27 -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=@linuxfoundation.org header.s=korg header.b=JUOTD3Qo; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243711AbhIMNjy (ORCPT + 99 others); Mon, 13 Sep 2021 09:39:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:33598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243068AbhIMNex (ORCPT ); Mon, 13 Sep 2021 09:34:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B1A0C6124A; Mon, 13 Sep 2021 13:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539620; bh=arBhUMgIy071O92zHpDMFw21GCoEGmEvMtconCL+aPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JUOTD3QouMcFdBvQFMCotXGg8rkX6vmOL9leN6O1Yq2SRh5zTxuQGDGGjRnVnc6lu aMEGdwZtMkeEe6WhyD4xYxTe/uD5RJ8WZ8OcOVSK6b/wcJaBuS7zvZnkeb/648ZHLV v30X8UYYr+BipvQA/J55VUHuub/lJNVndq2r4C9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongliang Mu , Sean Young , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 093/236] media: dvb-usb: Fix error handling in dvb_usb_i2c_init Date: Mon, 13 Sep 2021 15:13:18 +0200 Message-Id: <20210913131103.523438284@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 131ae388b88e3daf4cb0721ed4b4cb8bfc201465 ] In dvb_usb_i2c_init, if i2c_add_adapter fails, it only prints an error message, and then continues to set DVB_USB_STATE_I2C. This affects the logic of dvb_usb_i2c_exit, which leads to that, the deletion of i2c_adap even if the i2c_add_adapter fails. Fix this by returning at the failure of i2c_add_adapter and then move dvb_usb_i2c_exit out of the error handling code of dvb_usb_i2c_init. Fixes: 13a79f14ab28 ("media: dvb-usb: Fix memory leak at error in dvb_usb_device_init()") Signed-off-by: Dongliang Mu Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/dvb-usb/dvb-usb-i2c.c | 9 +++++++-- drivers/media/usb/dvb-usb/dvb-usb-init.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/dvb-usb/dvb-usb-i2c.c b/drivers/media/usb/dvb-usb/dvb-usb-i2c.c index 2e07106f4680..bc4b2abdde1a 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-i2c.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-i2c.c @@ -17,7 +17,8 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d) if (d->props.i2c_algo == NULL) { err("no i2c algorithm specified"); - return -EINVAL; + ret = -EINVAL; + goto err; } strscpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name)); @@ -27,11 +28,15 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d) i2c_set_adapdata(&d->i2c_adap, d); - if ((ret = i2c_add_adapter(&d->i2c_adap)) < 0) + ret = i2c_add_adapter(&d->i2c_adap); + if (ret < 0) { err("could not add i2c adapter"); + goto err; + } d->state |= DVB_USB_STATE_I2C; +err: return ret; } diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c index 28e1fd64dd3c..61439c8f33ca 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -194,8 +194,8 @@ static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums) err_adapter_init: dvb_usb_adapter_exit(d); -err_i2c_init: dvb_usb_i2c_exit(d); +err_i2c_init: if (d->priv && d->props.priv_destroy) d->props.priv_destroy(d); err_priv_init: -- 2.30.2