Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp123858rdb; Wed, 29 Nov 2023 23:27:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4c3/hy7SWDF08tyFSN1a+7b40ofMVaKWzB95xZBrcCZt4hB9D/y0e1J4i4psWFQed79RN X-Received: by 2002:a17:902:f54f:b0:1cf:bdaf:8390 with SMTP id h15-20020a170902f54f00b001cfbdaf8390mr15158147plf.60.1701329262352; Wed, 29 Nov 2023 23:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701329262; cv=none; d=google.com; s=arc-20160816; b=BQwMIXvTQwPyQNaiRqDo2ZgpkuU6lT1dlluQ871wo3iaA3k1oGDiOn68HLfRV8ff7D Q9XX8eN90fAgWxqMB4KXh0fV3yf+Zqd893MkNkdPdb+8UVeqpOVBMWQftB5KiiB45HCr bEAKkSo07AcQctMTxqraTQRsJSmJY4jYjLGtu+/7xDTMtkV1vUecHEQmHmkoyb6gctIW BMHfiAtIKOFkwV2vQdDlXu6jFWhCuIKq04cZy8XelQWZAdtv13djHaI66ur7vnj4AHX3 c4z3eL2NYaOUDXYPeCc7+3HFg93VU4fkz4CDpmJ5uRGvQB9KSMtF569x5cy5BUXgZnF+ +WNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=7WLNcsSt42LaGfjZQ98cMh59wBp+UL1asBOR9zkijns=; fh=3YsDNDRpkKQkDlxg+U6dAKncT3ZMeGqzPaHa+RMYP6M=; b=E/EMFIlvog3rZfwIFzhDYAv0weXM8HT/8LR6RfW5Uf78QP0G5rBQnRQxEkHg3uUWlM uFE5Y1l3DsBOR73THyzgiTyAUA4BXw4g3eYBDLiBi1yc5yxyqMB4gkgu705OeC/88Gc2 XjU6fUsZc1EPHzMvq9yNRlBhQUgx26E4s6vKDDKhMhSxsnOzI1dl9dJpqnyUpQYUMi1M BQdx6SAHzw6RUFoXCz0O2CfkXTwVLj+cLASs34pGvQjLfCas2JEzdHqKEamM7sKPFe+5 Ub6/PFNH+WPOHE6YD7bHmcX2hPGLKhtENgNqpEoNV3flQfQQ7EhPWAypi/fJuGBsgCT2 WGpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pxJZU+83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t12-20020a170902a5cc00b001cfc3295702si588475plq.109.2023.11.29.23.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 23:27:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pxJZU+83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id AEA2380E6C72; Wed, 29 Nov 2023 23:27:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbjK3H1Q (ORCPT + 99 others); Thu, 30 Nov 2023 02:27:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231713AbjK3H1P (ORCPT ); Thu, 30 Nov 2023 02:27:15 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1337510EF for ; Wed, 29 Nov 2023 23:27:21 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c8879a1570so8466871fa.1 for ; Wed, 29 Nov 2023 23:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701329239; x=1701934039; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=7WLNcsSt42LaGfjZQ98cMh59wBp+UL1asBOR9zkijns=; b=pxJZU+83KLExIo4EmVxqCv8wdgHTuKTa7225bk6VrXC9IIu0WKgfUQ3gvAeWL1jqdj rFWYWksY/yTgjUTaoYhuwDosGUv1IgJQR8/+FxzDHdpDpWr3uDEVmX/7xjUSeUe0jBIG WPzq/STIBN81BIX6ERFOJXLFz4iIbm7NG/8kG9N2fzWNAG/jUyudqO1p9Q064ve0UJQs VUUODqPWM0V9kqERyQswuNGkDOHG310OLZ2kusrCQJKlmDMjCNM/U1NJBn6R+rdytAZ3 5te/KyV4rbbgfhBAveiw+hBaBNa1fL2Faffj990MNBh8nDlocer0ikj1XG8haVdd/3GL Lkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701329239; x=1701934039; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7WLNcsSt42LaGfjZQ98cMh59wBp+UL1asBOR9zkijns=; b=h5dSIY9AQ+tewh8iam9o6+sh0ryjewQSWJhF18xOanvDokYleqFCSWBwxMPrjelIqL qyUz+iUCIzOGrT1smnd7dvKnNOWRIjOPo9N51NBvk6KGX0qzhZWa/WaWgl0XNiXSwUHP j8B/aOOmS7ZVEsgbtXbv6Aw2km/ljQXy7euDU32LiJht3xHKygd/rv4SmmLQn3+xO59D J5r0NaLUA1J9exaXjyTOptrRMRFzqYpWQRZvQwhjmS4uvXjNZ79zoy5O77Rr7GWebdNM wMyZN2d3PxWAGdCOtUUyS3PaR+Uu3dM99zVDCkr2livOV6gbHgof05SxrZ7zTPClZNb5 AFXQ== X-Gm-Message-State: AOJu0YzeBIHdifiR3m1fA+CU/L/YVzhjABUCoc/GblK416q6jXTAMu6R D/YLBeRMyaqIl6W/swr1UNo3AQ== X-Received: by 2002:a2e:8606:0:b0:2c9:af18:2e8c with SMTP id a6-20020a2e8606000000b002c9af182e8cmr5027808lji.10.1701329239279; Wed, 29 Nov 2023 23:27:19 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id n10-20020a05600c4f8a00b004053e9276easm4564118wmq.32.2023.11.29.23.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 23:27:19 -0800 (PST) Date: Thu, 30 Nov 2023 10:27:15 +0300 From: Dan Carpenter To: Sarah Walker Cc: Frank Binns , Donald Robson , Matt Coster , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] drm/imagination: fix off by one in pvr_vm_mips_init() error handling Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 29 Nov 2023 23:27:39 -0800 (PST) If the call to vmap() fails the "page_nr" is one element beyond the end of the mips_data->pt_dma_addr[] and mips_data->pt_pages[] arrays. The way that this is traditionally written is that we clean up the partial loop iteration before the goto and then we can say while (--i >= 0). At that point we know that all the elements thus far are initialized so we don't need to have NULL checks. Fixes: 927f3e0253c1 ("drm/imagination: Implement MIPS firmware processor and MMU support") Signed-off-by: Dan Carpenter --- drivers/gpu/drm/imagination/pvr_vm_mips.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_vm_mips.c b/drivers/gpu/drm/imagination/pvr_vm_mips.c index 7268cf6e630b..2bc7181a4c3e 100644 --- a/drivers/gpu/drm/imagination/pvr_vm_mips.c +++ b/drivers/gpu/drm/imagination/pvr_vm_mips.c @@ -57,6 +57,7 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev) PAGE_SIZE, DMA_TO_DEVICE); if (dma_mapping_error(dev, mips_data->pt_dma_addr[page_nr])) { err = -ENOMEM; + __free_page(mips_data->pt_pages[page_nr]); goto err_free_pages; } } @@ -79,13 +80,11 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev) return 0; err_free_pages: - for (; page_nr >= 0; page_nr--) { - if (mips_data->pt_dma_addr[page_nr]) - dma_unmap_page(from_pvr_device(pvr_dev)->dev, - mips_data->pt_dma_addr[page_nr], PAGE_SIZE, DMA_TO_DEVICE); + while (--page_nr >= 0) { + dma_unmap_page(from_pvr_device(pvr_dev)->dev, + mips_data->pt_dma_addr[page_nr], PAGE_SIZE, DMA_TO_DEVICE); - if (mips_data->pt_pages[page_nr]) - __free_page(mips_data->pt_pages[page_nr]); + __free_page(mips_data->pt_pages[page_nr]); } return err; -- 2.42.0