Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4616510pxj; Wed, 12 May 2021 09:18:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNMPk3i8MeVy2ER1I7F7nJhwDEiNC+s8gbK7dhPweltPOyYNa+tNzU39jKgUBjIjGOK7RZ X-Received: by 2002:a17:906:144d:: with SMTP id q13mr40212393ejc.458.1620836331275; Wed, 12 May 2021 09:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836331; cv=none; d=google.com; s=arc-20160816; b=03orxZaHIvoUlDJH86MdCaRZ/KKtuyoQaXD2L6TTudPgs8XQxiRZiuFvP8nANbqqrq 7fdUYKJ+vKY48V+AWrovORyQVRc6kMbvF8WBlOTbRmfGQgpq1fwymuXiUCONAFMQgSfa A9VuCFvuAg3UsCYR+g/m4goSObxM1EbF+aQvZq4g2vrIFW5M8FFywKkHMZxCRF2hgT8q Z+NCWf96jPJNd5psEQhFoKi0oWdkdoDvv5s23tiyQpDKZD8cEeigq8FchJkgy7/kj7rD A7UGerdKZqtmM2v7N+mzP5bkpMHPtVqhXoRHk+OO1JB6d8IdfFnOq72P3k8tiG4uCkTk 0ytg== 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=krkIY/n74zwXeIaNLEh5X1F88lGbqSLnlyx8soiz7Is=; b=PTCQRNyou2cv0M+3VXeV+wEbFyVBMpY0dYy5Cl0a5I07IwPhkKhyxz0ICm0a/WtP7S PJI/AuwEvaCt96oys3ujkVhZyNILRl/FfUEfjwA//aGz5H+opNmZL5sjm0Uz/TOVrUHu yXDE3B3vEkUbnwjybUPbMkRC2WL7OgjB6RhxpbOtemWT+0msmwA3uBASal1uo+nJBIW0 sfvqgBGbZAfavNGsDRsuwYyDxol534wZ4q2bV9tlz/rnZlRANYjpWyoYRFtn/XaWwU5N 6MH/OaAVhm9Qz8kSZ4VZMybGsftFKTFkNQufBMJKjwyqGUkFZOQx1H01vGkVLCpgZ9L2 i9eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OrZ2EpsV; 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 ke4si325291ejc.239.2021.05.12.09.18.26; Wed, 12 May 2021 09:18:51 -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=OrZ2EpsV; 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 S237124AbhELQNO (ORCPT + 99 others); Wed, 12 May 2021 12:13:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:48522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233343AbhELPbA (ORCPT ); Wed, 12 May 2021 11:31:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 226B661973; Wed, 12 May 2021 15:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832559; bh=uT4St2Xmo4LGUuzGAYbLPQpZNkJ7+0Vm+KVqVISREpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrZ2EpsVVp4QEaoKPbD99BMs2LP8AvmJjU92cmgdeS/GMNFT/1Ij7L2O2UIZ2Ws3N T3j/eV53bRDuZq5FWOs82h0LHcnBf+jmIxwnfjoFbRxT+C0heqss9NULpULondeG2q rlyeCBa5zCCJSo8gC0VLBbz0vk7qav7iM9RCQpJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Souptick Joarder , John Hubbard , Ira Weiny , Dan Carpenter , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 296/530] media: atomisp: Fixed error handling path Date: Wed, 12 May 2021 16:46:46 +0200 Message-Id: <20210512144829.532711187@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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: Souptick Joarder [ Upstream commit 16a5dcf7fbc2f5cd10c1e6264262bfa3832fb7d5 ] Inside alloc_user_pages() based on flag value either pin_user_pages() or get_user_pages_fast() will be called. However, these API might fail. But free_user_pages() called in error handling path doesn't bother about return value and will try to unpin bo->pgnr pages, which is incorrect. Fix this by passing the page_nr to free_user_pages(). If page_nr > 0 pages will be unpinned based on bo->mem_type. This will also take care of non error handling path. allocation") Link: https://lore.kernel.org/linux-media/1601219284-13275-1-git-send-email-jrdr.linux@gmail.com Fixes: 14a638ab96c5 ("media: atomisp: use pin_user_pages() for memory Signed-off-by: Souptick Joarder Cc: John Hubbard Cc: Ira Weiny Reviewed-by: Dan Carpenter Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/atomisp/pci/hmm/hmm_bo.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c index f13af2329f48..0168f9839c90 100644 --- a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +++ b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c @@ -857,16 +857,17 @@ static void free_private_pages(struct hmm_buffer_object *bo, kfree(bo->page_obj); } -static void free_user_pages(struct hmm_buffer_object *bo) +static void free_user_pages(struct hmm_buffer_object *bo, + unsigned int page_nr) { int i; hmm_mem_stat.usr_size -= bo->pgnr; if (bo->mem_type == HMM_BO_MEM_TYPE_PFN) { - unpin_user_pages(bo->pages, bo->pgnr); + unpin_user_pages(bo->pages, page_nr); } else { - for (i = 0; i < bo->pgnr; i++) + for (i = 0; i < page_nr; i++) put_page(bo->pages[i]); } kfree(bo->pages); @@ -942,6 +943,8 @@ static int alloc_user_pages(struct hmm_buffer_object *bo, dev_err(atomisp_dev, "get_user_pages err: bo->pgnr = %d, pgnr actually pinned = %d.\n", bo->pgnr, page_nr); + if (page_nr < 0) + page_nr = 0; goto out_of_mem; } @@ -954,7 +957,7 @@ static int alloc_user_pages(struct hmm_buffer_object *bo, out_of_mem: - free_user_pages(bo); + free_user_pages(bo, page_nr); return -ENOMEM; } @@ -1037,7 +1040,7 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo) if (bo->type == HMM_BO_PRIVATE) free_private_pages(bo, &dynamic_pool, &reserved_pool); else if (bo->type == HMM_BO_USER) - free_user_pages(bo); + free_user_pages(bo, bo->pgnr); else dev_err(atomisp_dev, "invalid buffer type.\n"); mutex_unlock(&bo->mutex); -- 2.30.2