Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3312515iob; Mon, 16 May 2022 19:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ0ijW1Ip3Sj/RPULS0hZY+GQgGp64Nt8eMam1Ke8+m3soEToX4ACOWmb1Gkd84ltQZYy5 X-Received: by 2002:a63:241:0:b0:3c5:fc11:ab56 with SMTP id 62-20020a630241000000b003c5fc11ab56mr17849893pgc.193.1652752967970; Mon, 16 May 2022 19:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652752967; cv=none; d=google.com; s=arc-20160816; b=yOhLPMyPcuGrANYJRZhfaoT+Ht81h9yfxtFECL/aw/43e9ykVyhPolQEB66ddg4kPB w7SpFmCqwJkiN+U/jcJc7d0u7CkE2kK9D/no/L7NgvTtqP+jWVUvKby58vhh0jIvb5qz azIjPjlsXeU7EYSJIEo5QRRnzLcX7XbASU7wZbxxHcs0wks4evsF6gZH1HGkS5GmK8vr e2Dw25j1I8s2NdNgZ1FdosXc57Jep5ySLxxvqXZGMhGCFha9YgBtZAzaP7aO9Dph9A5v /Eegjm/VweJbiGGSQD3iUFEjnpoqKc2E6XF22ImkSqz8y2Qja5fM8WAGJfE1j5XA2a6W uBNQ== 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=3xbWnY0/ofsJQTBqKjhkjGAFjhS1EOIhqYdJlsczoqM=; b=RmcgLMRV95afaIe1MBTnpvfGJqg9g0XQIGA94sAZG+NNDTyj3nKJoxIOq6fwVbkHJo h9o923KP/OpiXNQd1zWKWE7O7nX+bRauIXFmt0ruzctM7PVQj1Oa6uVitPBnhSQgEtAp qew+Qf/6vqKzpQ6r5ZXAVuiM/UosBrs4JyHo74uaBAi2vDM9XwO4G/Y2Lsex+3z0TV54 w5Pr7lM6ktyr9OXWFIvzzImhKmRXT64PRiDQP6K+5OKRuY75uW1sHHGiTX7nZ1lgRQO6 SS/eRyv9/wnJE3JpE8XfEbGs6zHJDbzWBk8RVvLdBAdgGDJcftjRjNyrMKRFVY51VhUD zU5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kl8RjbC9; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a634444000000b003aa67e7fef7si14413208pgk.776.2022.05.16.19.02.36; Mon, 16 May 2022 19:02:47 -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=@linuxfoundation.org header.s=korg header.b=kl8RjbC9; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346910AbiEPUQg (ORCPT + 99 others); Mon, 16 May 2022 16:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348275AbiEPT6c (ORCPT ); Mon, 16 May 2022 15:58:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 676CC496A0; Mon, 16 May 2022 12:50:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A35D8B81615; Mon, 16 May 2022 19:50:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3FB2C34115; Mon, 16 May 2022 19:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730622; bh=QtSTpg4s7bW+z7cb5PjOt/RnDgPxZ0RF5p2u0Qr7maU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kl8RjbC956fYRtKzIBjeApzPxgj++7vOxAlSLlz5Z6LkvUzIS62IHey680LY81e/0 biVBxOFUjTJB+LNgIoYvNvUg0AjYi9wFWrbjap6M1PXYMpf9Tlmst3QXk+SIhfKYgE L+6RXk4RTGmSl0zfxRPGyMspAJ0X/f21vsu2moA8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Lyude Paul , Sasha Levin Subject: [PATCH 5.15 017/102] drm/nouveau: Fix a potential theorical leak in nouveau_get_backlight_name() Date: Mon, 16 May 2022 21:35:51 +0200 Message-Id: <20220516193624.493092068@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Christophe JAILLET [ Upstream commit ab244be47a8f111bc82496a8a20c907236e37f95 ] If successful ida_simple_get() calls are not undone when needed, some additional memory may be allocated and wasted. Here, an ID between 0 and MAX_INT is required. If this ID is >=100, it is not taken into account and is wasted. It should be released. Instead of calling ida_simple_remove(), take advantage of the 'max' parameter to require the ID not to be too big. Should it be too big, it is not allocated and don't need to be freed. While at it, use ida_alloc_xxx()/ida_free() instead to ida_simple_get()/ida_simple_remove(). The latter is deprecated and more verbose. Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces") Signed-off-by: Christophe JAILLET Reviewed-by: Lyude Paul [Fixed formatting warning from checkpatch] Signed-off-by: Lyude Paul Link: https://patchwork.freedesktop.org/patch/msgid/9ba85bca59df6813dc029e743a836451d5173221.1644386541.git.christophe.jaillet@wanadoo.fr Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nouveau_backlight.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c index 12965a832f94..aa8ed08fe9a7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_backlight.c +++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c @@ -46,8 +46,9 @@ static bool nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE], struct nouveau_backlight *bl) { - const int nb = ida_simple_get(&bl_ida, 0, 0, GFP_KERNEL); - if (nb < 0 || nb >= 100) + const int nb = ida_alloc_max(&bl_ida, 99, GFP_KERNEL); + + if (nb < 0) return false; if (nb > 0) snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); @@ -411,7 +412,7 @@ nouveau_backlight_init(struct drm_connector *connector) nv_encoder, ops, &props); if (IS_ERR(bl->dev)) { if (bl->id >= 0) - ida_simple_remove(&bl_ida, bl->id); + ida_free(&bl_ida, bl->id); ret = PTR_ERR(bl->dev); goto fail_alloc; } @@ -439,7 +440,7 @@ nouveau_backlight_fini(struct drm_connector *connector) return; if (bl->id >= 0) - ida_simple_remove(&bl_ida, bl->id); + ida_free(&bl_ida, bl->id); backlight_device_unregister(bl->dev); nv_conn->backlight = NULL; -- 2.35.1