stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Chengguang Xu <cgxu519@mykernel.net>,
	Christoph Hellwig <hch@lst.de>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>,
	linux-block@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 36/40] block: release bip in a right way in error path
Date: Wed,  1 Jul 2020 21:23:57 -0400	[thread overview]
Message-ID: <20200702012402.2701121-36-sashal@kernel.org> (raw)
In-Reply-To: <20200702012402.2701121-1-sashal@kernel.org>

From: Chengguang Xu <cgxu519@mykernel.net>

[ Upstream commit 0b8eb629a700c0ef15a437758db8255f8444e76c ]

Release bip using kfree() in error path when that was allocated
by kmalloc().

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 block/bio-integrity.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index bf62c25cde8f4..1d173feb38831 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -24,6 +24,18 @@ void blk_flush_integrity(void)
 	flush_workqueue(kintegrityd_wq);
 }
 
+void __bio_integrity_free(struct bio_set *bs, struct bio_integrity_payload *bip)
+{
+	if (bs && mempool_initialized(&bs->bio_integrity_pool)) {
+		if (bip->bip_vec)
+			bvec_free(&bs->bvec_integrity_pool, bip->bip_vec,
+				  bip->bip_slab);
+		mempool_free(bip, &bs->bio_integrity_pool);
+	} else {
+		kfree(bip);
+	}
+}
+
 /**
  * bio_integrity_alloc - Allocate integrity payload and attach it to bio
  * @bio:	bio to attach integrity metadata to
@@ -75,7 +87,7 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
 
 	return bip;
 err:
-	mempool_free(bip, &bs->bio_integrity_pool);
+	__bio_integrity_free(bs, bip);
 	return ERR_PTR(-ENOMEM);
 }
 EXPORT_SYMBOL(bio_integrity_alloc);
@@ -96,14 +108,7 @@ void bio_integrity_free(struct bio *bio)
 		kfree(page_address(bip->bip_vec->bv_page) +
 		      bip->bip_vec->bv_offset);
 
-	if (bs && mempool_initialized(&bs->bio_integrity_pool)) {
-		bvec_free(&bs->bvec_integrity_pool, bip->bip_vec, bip->bip_slab);
-
-		mempool_free(bip, &bs->bio_integrity_pool);
-	} else {
-		kfree(bip);
-	}
-
+	__bio_integrity_free(bs, bip);
 	bio->bi_integrity = NULL;
 	bio->bi_opf &= ~REQ_INTEGRITY;
 }
-- 
2.25.1


  parent reply	other threads:[~2020-07-02  1:32 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02  1:23 [PATCH AUTOSEL 5.4 01/40] regmap: fix alignment issue Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 02/40] perf/x86/rapl: Move RAPL support to common x86 code Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 03/40] perf/x86/rapl: Fix RAPL config variable bug Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 04/40] ARM: dts: omap4-droid4: Fix spi configuration and increase rate Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 05/40] drm/ttm: Fix dma_fence refcnt leak when adding move fence Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 06/40] drm/tegra: hub: Do not enable orphaned window group Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 07/40] gpu: host1x: Detach driver on unregister Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 08/40] btrfs: use kfree() in btrfs_ioctl_get_subvol_info() Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 09/40] drm: mcde: Fix display initialization problem Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 10/40] ASoC: SOF: Intel: add PCI ID for CometLake-S Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 11/40] ASoC: SOF: Intel: add PCI IDs for ICL-H and TGL-H Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 12/40] net: usb: ax88179_178a: fix packet alignment padding Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 13/40] ALSA: hda: Intel: add missing PCI IDs for ICL-H, TGL-H and EKL Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 14/40] usb: usbtest: fix missing kfree(dev->buf) in usbtest_disconnect Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 15/40] spi: spidev: fix a race between spidev_release and spidev_remove Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 16/40] spi: spidev: fix a potential use-after-free in spidev_release() Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 17/40] net: ethernet: mvneta: Fix Serdes configuration for SoCs without comphy Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 18/40] net: ethernet: mvneta: Add 2500BaseX support " Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 19/40] tg3: driver sleeps indefinitely when EEH errors exceed eeh_max_freezes Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 20/40] ixgbe: protect ring accesses with READ- and WRITE_ONCE Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 21/40] i40e: " Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 22/40] ibmvnic: continue to init in CRQ reset returns H_CLOSED Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 23/40] powerpc/kvm/book3s64: Fix kernel crash with nested kvm & DEBUG_VIRTUAL Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 24/40] usbnet: smsc95xx: Fix use-after-free after removal Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 25/40] iommu/vt-d: Don't apply gfx quirks to untrusted devices Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 26/40] drm: panel-orientation-quirks: Add quirk for Asus T101HA panel Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 27/40] drm: panel-orientation-quirks: Use generic orientation-data for Acer S1003 Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 28/40] s390/kasan: fix early pgm check handler execution Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 29/40] s390/debug: avoid kernel warning on too large number of pages Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 30/40] cifs: Fix double add page to memcg when cifs_readpages Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 31/40] drm/sun4i: mixer: Call of_dma_configure if there's an IOMMU Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 32/40] cifs: update ctime and mtime during truncate Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 33/40] ARM: imx6: add missing put_device() call in imx6q_suspend_init() Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 34/40] scsi: mptscsih: Fix read sense data size Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 35/40] usb: dwc3: pci: Fix reference count leak in dwc3_pci_resume_work Sasha Levin
2020-07-02  1:23 ` Sasha Levin [this message]
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 37/40] nvme-rdma: assign completion vector correctly Sasha Levin
2020-07-02  1:23 ` [PATCH AUTOSEL 5.4 38/40] x86/entry: Increase entry_stack size to a full page Sasha Levin
2020-07-02  1:24 ` [PATCH AUTOSEL 5.4 39/40] kgdb: Avoid suspicious RCU usage warning Sasha Levin
2020-07-02  1:24 ` [PATCH AUTOSEL 5.4 40/40] sched/core: Check cpus_mask, not cpus_ptr in __set_cpus_allowed_ptr(), to fix mask corruption Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200702012402.2701121-36-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=cgxu519@mykernel.net \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).