Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5377669iog; Wed, 22 Jun 2022 18:53:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uHjun5klWSb5kKhoUXsB/r+4yIMK/FWCWlbtRPPF/ul4o3y9qJkM481JJRRe8zGC/6GptO X-Received: by 2002:a17:906:7292:b0:712:3880:3e7b with SMTP id b18-20020a170906729200b0071238803e7bmr5752641ejl.118.1655949185405; Wed, 22 Jun 2022 18:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655949185; cv=none; d=google.com; s=arc-20160816; b=kY3z0XfUo9TNs+7Srumq0fWaSSVEj4o3OBOwC8ZPskR6/M6ziwk3Q+2OF+ZgqhX6tm cs6H6CWAv5gf2nfLGAGgysJXNtbx0sq1r75ib2TeWbPDzqQPtIdNMBoAbWPPQqjQglGN NdAAYQTsA6cg+zbKQrN7MhKo5XxLyl23FWll1FuGqsxHeDWBs/Qm9lcVyXVyfULBTMzL C2XJ6ljVTs1+HEEynRBY+k2upxfKwo6BSPhR5H39B/MXcErSCL/gyHdXt8VSOEbUjzR7 s3Dv9B+Nk1yemWbKZRKlad6cdlBHEwhvorV82SWFbdA6Ez3k++n5+L622/1fJLjLdGs2 C0ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=XBccRW3f809STZYPXXYOmdRu7QvxDSYP9NM/SprVkxQ=; b=MrIPT3k5V5me6FqRXlch8F9Hq5ORSrelQWO5UOj87QDEQxRUyaGtDAvgM4Lyy4a1/R mfcC7APSuyDGCRKnhdv06plLb7R5GoCbel5bk7GEjdrGST0R5rpvsEdwSa8joPDhfgX1 eOQ60tgiUNCx5t5KkXrYcOS0sW3wDTxhKH50bV+Bv3r+cEd39VO0921QW3bRVrcm/lTp 2KFHk3SOo5LONh6qxdt2YXDqpwbQZ2XibpYUIOYTwUXF5BGQQSFU5J2orsL8c2BznBCo dhPZ//grTEBD5iv+BYj8WwxY22dTkLcrjd5y6uowmVp/JURKMGTlWz8DCq7NY/Z7W7yE kUtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hLQCWBlB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs12-20020a170906dc8c00b006e812fe9f78si20214784ejc.461.2022.06.22.18.52.40; Wed, 22 Jun 2022 18:53:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hLQCWBlB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1358800AbiFWBpx (ORCPT + 99 others); Wed, 22 Jun 2022 21:45:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358657AbiFWBpv (ORCPT ); Wed, 22 Jun 2022 21:45:51 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1451343AC8 for ; Wed, 22 Jun 2022 18:45:51 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id k12-20020a17090a404c00b001eaabc1fe5dso1087611pjg.1 for ; Wed, 22 Jun 2022 18:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language :from:to:cc:references:in-reply-to:content-transfer-encoding; bh=XBccRW3f809STZYPXXYOmdRu7QvxDSYP9NM/SprVkxQ=; b=hLQCWBlBMI7cXx2E87+ADwS9i4fRnadmJHUVnCjL+L3Ew5SWwQ755AeopCCQWXLrwZ sE+R9hJmUQKThtWQSBQJw4uiHGHVi/JLX9hl/ararv01AKc/kQZ6W3wOOAPGmtSKQLwM jYIcZu0muVb8lsmUyAJBZVVrpp4MpfMUZuOFbgqotSVOH3M4IViviOjqa7BTeEwA0FY8 mIBhuf3H12Ffp/NZ89ITdv0Duv8uFapXEdLawLEbXbkYGN1xzl14Wm4z/pPQNZesyB8L KDJu7GHEWHSQiG5qmCgGcCLdKY6Aoev2zmpDTHJjY6ODKYyZlHpW7SR0f94HNG1/Hvbk AVEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=XBccRW3f809STZYPXXYOmdRu7QvxDSYP9NM/SprVkxQ=; b=aT4lUALJ5Git7NGipESJDHoRx/COPX7eTE7qJmYl/G3pw23UmO6ZcypK12cD38Kl1V 74i5S3gMCwKhUBKVrtBVm/Fr9Zxta0KqN/lJKvqjYNAjhBHiAnmGaAIPry+ZUQIye8Gg fjkScqd8ksvDV/Fswy7NUkVQaMCak+Zlch2vmcDGpJY/7/ehBi+jQhAeP29CWZR8kUfc 4fIgQCncDCcPIX4oYM1XYfN2dfqi0QMFgKJNUDN6k367FtfVjIduaA2j225dY9gRiVZk 4MSMTUsvCkfChezRLZALywq3losZ/YmqKM8u3KMZxd30Suzwj1YlB1O7j1JkKiC5dANG Xorg== X-Gm-Message-State: AJIora+bOBCQ6S+TygNNHf5TZkbKZv4u4hdkNHJtTlXdXv/eMwHaMiX2 6Oq9CH7/1t7TFqJTj4IeogA= X-Received: by 2002:a17:90a:e7c8:b0:1e6:961f:999d with SMTP id kb8-20020a17090ae7c800b001e6961f999dmr1359069pjb.23.1655948750578; Wed, 22 Jun 2022 18:45:50 -0700 (PDT) Received: from [192.168.50.247] ([103.84.139.165]) by smtp.gmail.com with ESMTPSA id d26-20020a63735a000000b0040cba7ef9b9sm6901613pgn.9.2022.06.22.18.45.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jun 2022 18:45:49 -0700 (PDT) Message-ID: Date: Thu, 23 Jun 2022 09:45:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core() Content-Language: en-US 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 References: <20220509054441.17282-1-hbh25y@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 2022/5/23 09:57, Hangyu Hua wrote: > On 2022/5/9 13:44, Hangyu Hua wrote: >> 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); > > Gentel ping. Gentel ping.