Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2201969ybl; Sun, 18 Aug 2019 20:57:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnyJn31Lj3espUyF4YCJp+8RAE5K6txPtp+AceY2QpYU2wXEqHdDdAMpPedefc4Rn0PvDr X-Received: by 2002:a17:902:7286:: with SMTP id d6mr20665764pll.61.1566187050228; Sun, 18 Aug 2019 20:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566187050; cv=none; d=google.com; s=arc-20160816; b=v+eFAME4Z6QO4/qJJr7wVkaFMK9eh5mqm8GKcINbtYxMQeBjV6kDQA2ZxIwkgyV6h8 KBrBSyXn7PoU5VB7o8zoup768JLTWjTj3ti+H8yfRlOENNWDyyQOXcyX0FEFcvRVy1yC EByXHVsElJ2bOBzBGRo0Elnt5zPDaPfEMJSmPRfZ3mUtp/emT3pW/mrnnMvQzYPEw6E6 wF1Qp0u19G59clC3ps+5C9CXV/+vMMkt7rZyJLOPa0hZ7ZXPsNPx4IIiBJP8WaMcWSnQ glx4C24n8uU53Bcv7dPWabkL/c65w/n1wm0Mj903iHEc+31OB+lPfVk9cVsQKiPtupOt m4oA== 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=+Smd3VjhO146MLfA0Aqbu790Y5RY5fYddBsahwXXJRo=; b=cGJMWB1wPxqRS0GDDq2zqKQRuVP1hCCTNW0dVfRT7BfScsV4Qc0WtE+4c0IRzU56sA MVtkkdzHJnZU2dEICVUF6lYAT1HP0lolanO0OQw83MImDn60qWz/CPy7fEbVC1UgFWE4 CmubSo0ap1/w53JvYFjmL1xfzGRkGIBHOrs9VxeBBc11rS1tP56brSn+abtppjSn9ZT2 eRn5cIDj5AAYd8TJeUlLT2GRx+Bfw2To6GJnqJVIDVXHx8jqtmx325xNVC+30ewf0sPP XNmwhoHEPZ9SxEnqstomm+xqgropZmVv4mhKDyYAZufpYyfWTz+oe63GXzVP/T/XCRTZ k8GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si9516398pfe.204.2019.08.18.20.57.14; Sun, 18 Aug 2019 20:57:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbfHSD4Z (ORCPT + 99 others); Sun, 18 Aug 2019 23:56:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46272 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfHSD4Z (ORCPT ); Sun, 18 Aug 2019 23:56:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23E2D3091782; Mon, 19 Aug 2019 03:56:25 +0000 (UTC) Received: from ming.t460p (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E9D61001B11; Mon, 19 Aug 2019 03:56:19 +0000 (UTC) Date: Mon, 19 Aug 2019 11:56:14 +0800 From: Ming Lei To: Pan Bian Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH V2] block/bio-integrity: fix mismatched alloc free Message-ID: <20190819035613.GC3086@ming.t460p> References: <1566176353-20157-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1566176353-20157-1-git-send-email-bianpan2016@163.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 19 Aug 2019 03:56:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 19, 2019 at 08:59:13AM +0800, Pan Bian wrote: > The function kmalloc rather than mempool_alloc is called to allocate > memory when the memory pool is unavailable. However, mempool_alloc is > used to release the memory chunck in both cases when error occurs. This > patch fixes the bug. > > Fixes: 9f060e2231c ("block: Convert integrity to bvec_alloc_bs()") > Signed-off-by: Pan Bian > Cc: stable@vger.kernel.org > --- > V2: add Fixes and CC tags > --- > block/bio-integrity.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/block/bio-integrity.c b/block/bio-integrity.c > index fb95dbb..011dfc8 100644 > --- a/block/bio-integrity.c > +++ b/block/bio-integrity.c > @@ -75,7 +75,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, > > return bip; > err: > - mempool_free(bip, &bs->bio_integrity_pool); > + if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) > + kfree(bip); > + else > + mempool_free(bip, &bs->bio_integrity_pool); > return ERR_PTR(-ENOMEM); > } > EXPORT_SYMBOL(bio_integrity_alloc); 'err' is still reached in case that 'bs' is valid, so fix nothing. Thanks, Ming