Received: by 2002:a19:651b:0:0:0:0:0 with SMTP id z27csp3745838lfb; Mon, 9 May 2022 03:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygJzYDtyKH2ZifFJHAGkSQ6t4gm+YpvJRg1NeqCS+KpwiOKssOGA7BtvmaOYn7O+roR8Ie X-Received: by 2002:a17:90b:4c47:b0:1dc:3bf4:e3b1 with SMTP id np7-20020a17090b4c4700b001dc3bf4e3b1mr17583465pjb.223.1652091161885; Mon, 09 May 2022 03:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652091161; cv=none; d=google.com; s=arc-20160816; b=eTVl07bTmlTwe9vryPyb5KCHv/lCTDPMUGWLDGm4EMUjFYWolS+bDZXN9vgqtp4emH ulgfTGjRovv+Ta7C/cOp6DuG6yvAdA0ksrsk6vpuzO37My7PZHPQaXJsxczYqF7wKwxa KoIlsnpSsHjKE0DsHRpjc1X5BgzOAeBPInDvnUc8GJCCVZS/7l5lfB44QmCIusZirxqo gbOWZE9IlACkOET7pyBkWRT59pX9/LVydyalbIgntj+Z4EhIUCRK4UdtP2bAWjs0bRF3 af1nB3anYDSOj6GKR+DzpwvYfzVpwKdBoloIPK/5WsvGwQ3xYd084FklC4dPQImFrb0U xRCg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=cicmyo9fma3vroeKIGErP7E3mBkjABO4msZ5eM9hcRo=; b=jv7eIK8Uc7TExiFzJZwNdhwGAgQ2lm8DUKF+dLauvV9KqZTv+bc4DI2ZbN+swD7qv7 UpHivicbCCoFOwZ+tPV6b7hR7SeO3NOccJlTtVcyPIuPkQEGNToZ8wSnws4lOYZ76wCr Q53MWTrV/N59cDAKUCPTfr3Y5quti7gNe37tQRZoA6GADUe6i5kzcVE+DeiMSxQtUKgk fZU0zotwZr1S4Bc9em7OGvDdDiu0CdrbGxrpaBfX/UKes/tOQXRB09yKmgLK20asjFZZ zKDUovREXJxZj4L6V8CJXxoPlqG/0TWAI/DegRFizwOVwzEoA5ZapbL6lZwJw9ijxyu/ 7lKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LVuNP+WY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m13-20020a17090b068d00b001ca97924abdsi12628687pjz.115.2022.05.09.03.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:12:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LVuNP+WY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E4F3423E35B; Mon, 9 May 2022 02:51:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233473AbiEIF7i (ORCPT + 99 others); Mon, 9 May 2022 01:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234625AbiEIFuO (ORCPT ); Mon, 9 May 2022 01:50:14 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDB55111B95 for ; Sun, 8 May 2022 22:46:20 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id n8so12886234plh.1 for ; Sun, 08 May 2022 22:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cicmyo9fma3vroeKIGErP7E3mBkjABO4msZ5eM9hcRo=; b=LVuNP+WYky7iLeP1k2Esgi1WbqIrqsoqJLN6SppMoRPjnzlapPl5j2vLCaTAASNGCj 0BOozjxdYFgAjuO8gs2O0SS28UuL2UAFIEQuZPy4GVVRgKu0sIGcOeTAfd10TdwhX8or mUt362oP7ewMTSS3xbLVpPWei4pi5tDmfoK03tedVoYoIDNLGVXv3tIMe166REfQ07oY b7mS9azClsKeSWK8A/KfX5Tx16wgkZ4NdnuwbHnnO0r8OyXSFC3QShWCAbhgWkWFuJ2Z CDPizlVVXkIXMnq6Z/gsquiQnheCm+X3DLIEVuDJflkWQQSbwh9S96e4IuLu/Z7db/Mp EJ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cicmyo9fma3vroeKIGErP7E3mBkjABO4msZ5eM9hcRo=; b=YEiKhdF/2Fd+cRKwC/fWCh+sIxwNe9u/ozZQNnpRj+j40SgGyVwglc/gqVMf9G0LfI +OrP9A6nTR67Zt3j3lLmkwaCwBrNeZDqH8sUhTK5hfXNMYDvXmMqmqGeG3E/BH9yIF8Z QxcxyiC/pLaMnn7+y80DsWEBY1DAW3HSm021IjRfPxAvK2utsW17A4d/qXAvuV/H10ZC Q48QSXUO5DCLPIMXWZgn/qHIRAI/4OhIUryTnKiCo3DwDOu9fWw+tVR3VObIyG/Jy/sv sH3D593uzHlIif0y9+IDWaYCJRZPFrj4Lt04sOLuyZHZmUseFe7bIq6BSo2T5Sq10T+a 9L3Q== X-Gm-Message-State: AOAM530tbQ1pus1shtWDQzze3Svc9GzTrGR0pAyaef0t/ShyyuiqHjvJ IpKsBN8auuPU4/oDvsxh97U= X-Received: by 2002:a17:90b:694:b0:1d9:6a2e:bc9 with SMTP id m20-20020a17090b069400b001d96a2e0bc9mr24621202pjz.169.1652075119609; Sun, 08 May 2022 22:45:19 -0700 (PDT) Received: from localhost.localdomain ([103.84.139.165]) by smtp.gmail.com with ESMTPSA id m13-20020a170902db0d00b0015eb200cc00sm6104625plx.138.2022.05.08.22.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:45:19 -0700 (PDT) From: Hangyu Hua To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core() Date: Mon, 9 May 2022 13:44:41 +0800 Message-Id: <20220509054441.17282-1-hbh25y@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org map->handle need to be handled correctly when map->type is _DRM_SHM or _DRM_CONSISTENT just like map->type is _DRM_REGISTERS. Fixes: 8d153f7107ff ("drm: update user token hashing and map handles") Signed-off-by: Hangyu Hua --- drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c index fcca21e8efac..2b3f504c5f9c 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -344,6 +344,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset, if (!list) { if (map->type == _DRM_REGISTERS) iounmap(map->handle); + else if (map->type == _DRM_SHM) { + dev->sigdata.lock = dev->master->lock.hw_lock = NULL; + vfree(map->handle); + } else if (map->type == _DRM_CONSISTENT) { + dma_free_coherent(dev->dev, + map->size, + map->handle, + map->offset); + } kfree(map); return -EINVAL; } @@ -361,6 +370,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset, if (ret) { if (map->type == _DRM_REGISTERS) iounmap(map->handle); + else if (map->type == _DRM_SHM) { + dev->sigdata.lock = dev->master->lock.hw_lock = NULL; + vfree(map->handle); + } else if (map->type == _DRM_CONSISTENT) { + dma_free_coherent(dev->dev, + map->size, + map->handle, + map->offset); + } kfree(map); kfree(list); mutex_unlock(&dev->struct_mutex); -- 2.25.1