Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4467516pxa; Mon, 10 Aug 2020 09:43:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRc6aEupCt6JAMqKL3ikr+EkM3q/uLdNtJ8vNvGhXE3995gtK4Pfm1xmZ8NJyiCDb77nJP X-Received: by 2002:a17:906:f9d7:: with SMTP id lj23mr23790062ejb.500.1597077794624; Mon, 10 Aug 2020 09:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597077794; cv=none; d=google.com; s=arc-20160816; b=s7eg/E5PqUyjKXd49xZpAtvOxN/nYEkqgjnIDCkVutIRtMWz32n38BNWWDMRrnxk3j GEv8Yz1gikhxuXBHD/vK7LJREVWBlWrZcWCHT4iUTZYbkNAT23+hNLldYLKhcbTXpS2C RnFgb0dKLOS7n6PBe+owLEw3Fe0X60+FHVbiyiqhFyJyHw6iuC4BpxPy4V+G5WJwOJqj Wp4R7UqFYAnzpwVsSJz0n8RGBfqboTqUclxrEZmzdC0aU2nEK1ugOCxs76eBI3k/tWjG pG9s3HgHYsVP7QPwqQSemzOfMI6z2Eg02E0brAh19MPtju94iZGlFSkV54XgrbQkWsNW 9iaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=edrzXBGOkcZHqy9Q35S2FP5qynpQhmto6GT3W4hF9CY=; b=byZGEksbK+iBE165ge56Jb5YVQ/Z82TKp9udv4Vj05EdUFpMKulFLsOQrg+DZ0Em82 hcEYhrROgWkE8TJ0Sbu0VkFgWf7J7jjqYrOLA9/wJS7RMoB8lH1UgWvWEaljufcSjM8P 9WRLtuyYCUVK8c1L7S846aZohhchSQ/bQEEz4ezsMDmZMbOAW2rtWBA7QZ8OtQ/H3xVw xblYMo8JIYOonNdzE33T0e97pMaH1JMCA5Au423IM/8zCKxytIkcIWTCCIAaExhQ4JJF eIBQ1s/TUf7ZMNVDGK3tX8kNyZzipLrPGWKA7viOtd3siqsaUrtaMaghXufVwOSBmS4m Eqfw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si10727662eji.444.2020.08.10.09.42.51; Mon, 10 Aug 2020 09:43:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727866AbgHJQl5 (ORCPT + 99 others); Mon, 10 Aug 2020 12:41:57 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:47742 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbgHJQl4 (ORCPT ); Mon, 10 Aug 2020 12:41:56 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 8B77A1C0BD6; Mon, 10 Aug 2020 18:41:52 +0200 (CEST) Date: Mon, 10 Aug 2020 18:41:51 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Qiushi Wu , "Michael S. Tsirkin" , Sasha Levin Subject: Re: [PATCH 4.19 25/48] firmware: Fix a reference count leak. Message-ID: <20200810164151.GC24408@amd> References: <20200810151804.199494191@linuxfoundation.org> <20200810151805.452009812@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="UFHRwCdBEJvubb2X" Content-Disposition: inline In-Reply-To: <20200810151805.452009812@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --UFHRwCdBEJvubb2X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Qiushi Wu >=20 > [ Upstream commit fe3c60684377d5ad9b0569b87ed3e26e12c8173b ] >=20 > kobject_init_and_add() takes reference even when it fails. > If this function returns an error, kobject_put() must be called to > properly clean up the memory associated with the object. > Callback function fw_cfg_sysfs_release_entry() in kobject_put() > can handle the pointer "entry" properly. Okay, but... does that mean err_add_raw: should be using kobject_put(), too (w/o the kfree)? It is strange to have different error handling for different error paths. Best regards, Pavel > +++ b/drivers/firmware/qemu_fw_cfg.c > @@ -605,8 +605,10 @@ static int fw_cfg_register_file(const struct fw_cfg_= file *f) > /* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ > err =3D kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype, > fw_cfg_sel_ko, "%d", entry->select); > - if (err) > - goto err_register; > + if (err) { > + kobject_put(&entry->kobj); > + return err; > + } > =20 > /* add raw binary content access */ > err =3D sysfs_create_bin_file(&entry->kobj, &fw_cfg_sysfs_attr_raw); > @@ -622,7 +624,6 @@ static int fw_cfg_register_file(const struct fw_cfg_f= ile *f) > =20 > err_add_raw: > kobject_del(&entry->kobj); > -err_register: > kfree(entry); > return err; > } --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --UFHRwCdBEJvubb2X Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl8xeM8ACgkQMOfwapXb+vKP7QCgvXf4MTqkSx6rLOBaewd+iJzC 3XoAoLM1R4UvFXeJf1CqodIDMu3yYzu8 =pWli -----END PGP SIGNATURE----- --UFHRwCdBEJvubb2X--