Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1310762pxk; Mon, 31 Aug 2020 16:03:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+QlqswD2ZTnGm+sVOQo4vKP3E5sN9GbjFNcjuWuZk65Nf9cxO5cDwf03PJAlPvOoLg2dL X-Received: by 2002:a17:906:a415:: with SMTP id l21mr972409ejz.431.1598915003386; Mon, 31 Aug 2020 16:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598915003; cv=none; d=google.com; s=arc-20160816; b=ET7IsJNUpG+7udSlfVKK7H8xkTtPSKlWwPCVGDz+jKyYfd3vmndOMtTGcU3DevYs0j QFRmstSPzHWrvHEwN0UdtRhsn/7ZcJb5YdRnGAZALEsaMW1vw9PM2U9WGDXhOQ7hRtT3 jo6buvfGqPFMpTajX9HwDvnOsRnTHV5RHRmYtXOYSBdMq1tpcDdql6XRw+5352PNeFOA qpjQt+kWIt2vLxne83UJGqud/Ipqa8pd/AGUSAyQGONCaAQbHTgeSMIR3tRUOcY3ai2d JevwiuUGvl7PafPrgjOwMCsJtr4fIjFLATr7q7Xk8v1+H6TxBHXe6IVxPWedmY96aZAi Gz5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=U4+uhTBpQ4TnYUC3EzzBpVleBFNuIQlKM1znnPHB1ac=; b=Um4qU8AD4yHPmpqYotGwIZSgCZS4cc8miJ480gNQB3L5kH2GRMUR9X13RPM0gQcQzN dxjQE2Xz05PIvhmaaTc2H4Pfg+FYMt6bmTwVS2GMbAxPwVuHhB6JDHQeV0l7MLOdtp32 AEFQJcYUPouZRw6MH+BzeZcRZCR9GSiKl4zKsU8TawTsdYiTpYh4ow9bUt/lAaYVQ9oa jMCuHken/Y5wJDRWCxGMkIPhUS06Kd3ZVtmB8qiemmDBacCEh57Uz/0ppgQhlrtI+hLd 2BAj8DWLPph9AcHfMi4frEM00qrIWMDdXc6Wbwg1HGhdEbwwa5iADWVn3X6w7XdhLMTu MczQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pFnUe2iZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt2si6181150ejb.597.2020.08.31.16.03.00; Mon, 31 Aug 2020 16:03:23 -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=@gmail.com header.s=20161025 header.b=pFnUe2iZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730392AbgHaWIH (ORCPT + 99 others); Mon, 31 Aug 2020 18:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729173AbgHaWIG (ORCPT ); Mon, 31 Aug 2020 18:08:06 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7435CC061573 for ; Mon, 31 Aug 2020 15:08:06 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id q1so633200pjd.1 for ; Mon, 31 Aug 2020 15:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=U4+uhTBpQ4TnYUC3EzzBpVleBFNuIQlKM1znnPHB1ac=; b=pFnUe2iZ3ov4n6I4Jfr63UCW7Vt5Hu/bWRsHROs5W7Ba6/+8R2TaKQ0Ij7+5z0TvDB FJk88pG+iRs9LDOyxoh1ycpMKmobBTn6W646xKcpVACyv247icoEiIzzWqD97vvbqYlB 0BJR3ko28RdwulkwQDmpdbfwys9NOOOgSzDex8bmKSoY2bdauLzaJPBpqmhyqs0ytQR+ 5//3v7/Ol7Lwv6gYZz9nJx5qFMjL+A9RZqMe45sLAPbYUg4JOG7/UCcC2EoNv8cXefE7 wHvhVIagg6mSAVN8X6xvZoAdYESL2F/MIIupn4S2m65CnlHXGS3tq6b/aSsG+dBeKmGt 1nyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=U4+uhTBpQ4TnYUC3EzzBpVleBFNuIQlKM1znnPHB1ac=; b=U0JPb0mmDOkkLz5c7jy/AamO5fPHf/apvasQvXW+jd63qn5f7BDuJh0C6MyNGmydyV jly+pP85kmXaAZ1+yt8ks8Erph267AY+cocSXxYoF3xnTEDV3v3GEGg0JN7G+NXCdZWD lv3cqlEVCI5rwM2HfVJtldTy7WBkOLu7XwLaAtnC4trvLRaohyaOjtdLuXVCXtCH8jy/ +06XTmh9WpsDcDo5gMJBy3jcr6ews2j5z1+zao5wFE4o35EfA5eMW0VCNmd9ehu6DgP+ xH0XCXlwiP0DOnoyljQmYrxI/tCKvikhcRrc8chH8ifWUuPj2V/F0x7+kWJeY2A2nxME OFiw== X-Gm-Message-State: AOAM531oYMZS+b0EzBQZUEWfHwJY+XJhqf6C9hoqma9PUSvNBTJdTT6/ GPSs+29KiX3HXceYmuO4e42/W/avpawP8g== X-Received: by 2002:a17:90b:3284:: with SMTP id ks4mr1195295pjb.116.1598911685771; Mon, 31 Aug 2020 15:08:05 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([122.167.39.120]) by smtp.gmail.com with ESMTPSA id i20sm9150452pfq.204.2020.08.31.15.08.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Aug 2020 15:08:04 -0700 (PDT) From: Souptick Joarder To: akpm@linux-foundation.org, jhubbard@nvidia.com Cc: jgg@ziepe.ca, dan.j.williams@intel.com, gregkh@linuxfoundation.org, arnd@arndb.de, timur@freescale.com, galak@kernel.crashing.org, linux-kernel@vger.kernel.org, Souptick Joarder Subject: [linux-next PATCH v3] drivers/virt/fsl_hypervisor: Fix error handling path Date: Tue, 1 Sep 2020 03:37:47 +0530 Message-Id: <1598911668-6178-1-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org First, when memory allocation for sg_list_unaligned failed, there is a bug of calling put_pages() as we haven't pinned any pages. Second, if get_user_pages_fast() failed we should unpinned num_pinned pages instead of checking till num_pages. This will address both. As part of these changes, minor update in documentation. Fixes: 6db7199407ca ("drivers/virt: introduce Freescale hypervisor management driver") Signed-off-by: Souptick Joarder Reviewed-by: Dan Carpenter Reviewed-by: John Hubbard --- v2: Added review tag. v3: Address review comment on v2 from John. Added review tag. drivers/virt/fsl_hypervisor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c index 1b0b11b..efb4e7f 100644 --- a/drivers/virt/fsl_hypervisor.c +++ b/drivers/virt/fsl_hypervisor.c @@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) unsigned int i; long ret = 0; - int num_pinned; /* return value from get_user_pages() */ + int num_pinned = 0; /* return value from get_user_pages_fast() */ phys_addr_t remote_paddr; /* The next address in the remote buffer */ uint32_t count; /* The number of bytes left to copy */ @@ -174,7 +174,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) return -EINVAL; /* - * The array of pages returned by get_user_pages() covers only + * The array of pages returned by get_user_pages_fast() covers only * page-aligned memory. Since the user buffer is probably not * page-aligned, we need to handle the discrepancy. * @@ -224,7 +224,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) /* * 'pages' is an array of struct page pointers that's initialized by - * get_user_pages(). + * get_user_pages_fast(). */ pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); if (!pages) { @@ -241,7 +241,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) if (!sg_list_unaligned) { pr_debug("fsl-hv: could not allocate S/G list\n"); ret = -ENOMEM; - goto exit; + goto free_pages; } sg_list = PTR_ALIGN(sg_list_unaligned, sizeof(struct fh_sg_list)); @@ -250,7 +250,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) num_pages, param.source != -1 ? FOLL_WRITE : 0, pages); if (num_pinned != num_pages) { - /* get_user_pages() failed */ + /* get_user_pages_fast() failed */ pr_debug("fsl-hv: could not lock source buffer\n"); ret = (num_pinned < 0) ? num_pinned : -EFAULT; goto exit; @@ -293,12 +293,12 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) exit: if (pages) { - for (i = 0; i < num_pages; i++) - if (pages[i]) - put_page(pages[i]); + for (i = 0; i < num_pinned; i++) + put_page(pages[i]); } kfree(sg_list_unaligned); +free_pages: kfree(pages); if (!ret) -- 1.9.1