Received: by 10.223.185.116 with SMTP id b49csp5282506wrg; Wed, 7 Mar 2018 09:10:24 -0800 (PST) X-Google-Smtp-Source: AG47ELvDzxjzCdiIJA424fouaRNqGTBH4VbxQOGg/PJhTbMiDejbKwXmLqOqRHDB0FYhrp8dcx0L X-Received: by 2002:a17:902:6717:: with SMTP id f23-v6mr13131616plk.188.1520442624821; Wed, 07 Mar 2018 09:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520442624; cv=none; d=google.com; s=arc-20160816; b=WS+Imzjfwcdw7pC5R6IsnaqVTFbRoF67p0O9zheY21ndW8vH5FZnzaxvQ1sC7OfNXS rqbQ+AA3QEx0XoW+ptoBvXeKldBLl7ekvAhnGAu9XezTAyAhPLFuSwZZmz6oDUQut2qb LE74Ld0VIWY8zKOHF1bPPk9hhdUUWSeW61Kz4DtjCWShkB2DMluLfPkY9fOnOpSEKwdI 1T0MieBfOUKZSj2nSlznngBOY2B65eV9ig/5e2KAXK/UmeCFuLl0dIiP8Y2g08cE8uC/ KSYK8f+Sgeg3ayQmjVmf4L9Alr41vhRtyS2K+6U6uRNucXl9boibuKxrDgPD/q1Qoim+ KMQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=TqbpigFOdw0cbj/4GW0Zb6upOGvVQoqhGOWfUd3y6zE=; b=z72cuJxa3erhDIASYhQhUcW1xZFSiTEePbTr7Qt00q4MvSVxYwMtvCtIVS02bR5gAL tjb1bT9Fi6gAzwdB6yfDgivfbQkK+4TOYUK8WCY7qPIDOViUbrwOQkgGrTQkKAKuKAEO 8xdd2zEv5VMLGaJGxFLYXRWYxwHOYcMvobDZ2JA5EhFjMWkf+pEcwYq/YyOa9bikVtUv gM2ZiJHPHIYwSZXjRr1dgZXju96LSQIC37PXntasq8W5t9vH87RRPChhWWg3aqn8Bcfz vdigmqz/mUnRa7oQfPy2qT75OSLizuNbkT0777513pBaoc1xDBA3Y2gyxImJzzlDz3up o75Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=lJTTqhmC; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s190si11610476pgc.510.2018.03.07.09.10.09; Wed, 07 Mar 2018 09:10:24 -0800 (PST) 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; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=lJTTqhmC; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934104AbeCGRHC (ORCPT + 99 others); Wed, 7 Mar 2018 12:07:02 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33694 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933533AbeCGRG5 (ORCPT ); Wed, 7 Mar 2018 12:06:57 -0500 Received: by mail-wr0-f196.google.com with SMTP id v18so2926868wrv.0 for ; Wed, 07 Mar 2018 09:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=TqbpigFOdw0cbj/4GW0Zb6upOGvVQoqhGOWfUd3y6zE=; b=lJTTqhmCork+2/DFrsXantgpQQNFLovOVXu8S2n+OosWRxYdiWuxERENZ1QUGdIduX oLyYTeIk4CR2/oPv4UduU6ry0As/cRIQm+UNAbrsuO/HNVieTIe1V1CLu0znqroABoOb PHFuErwLWGvVhQL5eqofhjS/bESJLb/eBvhhdVENm25+FemD7R6BpzuypnNKf2bHk5XH Sj35LE/7z03xVst47fi9YUYyW0onvst+895pg6/RbfvUXzw+yCs9wwKViDT6eLPqkDY+ N2Bca8f8ELzBZPVlk/bMAbX4ZJJBLzR9Eln2wi7c3GW3q4soR/iVZnve05UNJlAD5b8c 7EDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=TqbpigFOdw0cbj/4GW0Zb6upOGvVQoqhGOWfUd3y6zE=; b=J7xeVCemYJv5dcTmRb8bwAhFlARoAYG0ZRegwbReue15VY9kukW3Fn/bT15XPuSoyM XahNigAjQEBPeayPjaanoTKxQRMTjmqNxxbqTCkNQFuTwNCot5Vf5GZh9hBZVmgnC8/F Mc8BtW1uxRJcOCjghZbZwDUw3M08sYxIdTHV5JVe2yalKwlpMnF67Rt7ZKU0dyUUxs0o V3N/F1RTkKVuu5BdRx4nFJYKOOuvi/bpS9Q40vB2dAzmknpFTB58aZsWvznSmR1u+x62 OuliFhW3JM5rsJhK8hvS9eHA13WQ0AImmj20TVSBrjYCWEWf1sNvj6CgOxNro5+VA3wT TOdw== X-Gm-Message-State: APf1xPDGRpfXV8bXot4N/wSFV+jzXdLrGaAgidTjPojPoANhrgg2oruR 6MVh6W7fa4dOwKHL91Dm7lWMOg== X-Received: by 10.223.151.129 with SMTP id s1mr20771149wrb.206.1520442416477; Wed, 07 Mar 2018 09:06:56 -0800 (PST) Received: from [192.168.0.153] ([95.146.144.186]) by smtp.googlemail.com with ESMTPSA id 8sm17013035wmf.13.2018.03.07.09.06.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 09:06:55 -0800 (PST) Subject: Re: [PATCH 3/6] lib/scatterlist: Do not leak pages when high-order allocation fails To: Bart Van Assche , "linux-kernel@vger.kernel.org" Cc: "tvrtko.ursulin@intel.com" , "hare@suse.com" , "jthumshirn@suse.de" , "axboe@kernel.dk" References: <20180307124712.14963-1-tvrtko.ursulin@linux.intel.com> <20180307124712.14963-4-tvrtko.ursulin@linux.intel.com> <1520439389.2890.16.camel@wdc.com> From: Tvrtko Ursulin Message-ID: <16b39b14-a59f-d184-b4f5-4c184f227ed5@ursulin.net> Date: Wed, 7 Mar 2018 17:06:55 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1520439389.2890.16.camel@wdc.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/03/18 16:16, Bart Van Assche wrote: > On Wed, 2018-03-07 at 12:47 +0000, Tvrtko Ursulin wrote: >> diff --git a/lib/scatterlist.c b/lib/scatterlist.c >> index 9884be50a2c0..e13a759c5c49 100644 >> --- a/lib/scatterlist.c >> +++ b/lib/scatterlist.c >> @@ -493,7 +493,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order, >> { >> unsigned int chunk_len = PAGE_SIZE << order; >> struct scatterlist *sgl, *sg; >> - unsigned int nent; >> + unsigned int nent, i; >> >> nent = round_up(length, chunk_len) >> (PAGE_SHIFT + order); >> >> @@ -517,11 +517,12 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order, >> >> sg_init_table(sgl, nent); >> sg = sgl; >> + i = 0; >> while (length) { >> struct page *page = alloc_pages(gfp, order); >> >> if (!page) { >> - sgl_free(sgl); >> + sgl_free_n_order(sgl, i, order); >> return NULL; >> } >> >> @@ -529,6 +530,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order, >> sg_set_page(sg, page, chunk_len, 0); >> length -= chunk_len; >> sg = sg_next(sg); >> + i++; >> } > > Since the entire sg-list is zero-initialized before this loop starts, since > the sg-list is not chained onto another sg-list before this function returns > and since sgl_free_n_order() checks whether or not each page pointer is NULL > before freeing it I think we don't need the new loop variable 'i' and that > we can call sgl_free_order() instead of sgl_free_n_order(). Yes true, I've only realized that in a later patch. Can rebase to move that change earlier in. Regards, Tvrtko