Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp595130iog; Mon, 13 Jun 2022 08:49:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj4smJ/zRG25HIHxqiuh5JacFBWn5jDznsFvjOuJkK60vPwr1q/+NAsbqJid6Jk7/EzrCO X-Received: by 2002:a17:90b:1651:b0:1e8:3e9c:801 with SMTP id il17-20020a17090b165100b001e83e9c0801mr16395809pjb.235.1655135351991; Mon, 13 Jun 2022 08:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135351; cv=none; d=google.com; s=arc-20160816; b=b+IStkvMyXVSiix7893ietYM4047r+DGSm3ugm7Z2on89PvaSfWXXljSEvznVauObZ Vxigf9hZ2wsfFh2Eg9xQJecxyL4AMla4gCks1U2dUrIGStmMtME+9XAV0Ogf8RE4vD21 SiBzH+/2yu+/bLPK5OAfim6OwJfzEL6cjSTRAwPpMNHQESJQJlNQf+2ldR0D2u4r7O0M BC65Stx5YOhgvIO0cFzr9C5fl5OtaMKFo3bz2eNOeXNjsS5ez5w+OHDKYoRtfukNJEKG wwy2QC4LgegscNc0dDMni5l/YEaOJUuEO9X8UPJEJAG924+1YAgqt5XfMagzEfz1GUQY Gp3A== 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=1hBnCeIGPGDXYfmXfnAN59Y1kgSM3DIodRtbZsmkZzg=; b=RXwaRiHHOXMOhNXsgU7S8IGQn6/DXp82+Mhf3gBmGElRdprUfcpy9ZBDGmkHwVyMso xT+ghSeCCwp7RUKpOzx1Z9XEqcl2U1GRaePYrf8Y7GTPNeJvtAM6FDsDUqYKz7v7zVVu ZQGDwFGFdYNCQq5q3gQPD61QDp5r0OpNZLqnQHG4xJr509c4/FmQn+fsdOJ+2m4NPXaJ thFXeuI3P/Rt8VYIdXarJdMTKJ3a3Z93CFCb9zhBjmoACd4/Ad+9CdSCKsF5su5wsPQV aDNEJnvrVcWIUnChywY07GVVkaDgDripe/OuthB1gHPmjZQUYtPyKWMO/gVPmNHU6xPT 3byA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1c3EbDFH; 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 z3-20020a1709028f8300b0015d0f3a4ac5si9386617plo.300.2022.06.13.08.48.58; Mon, 13 Jun 2022 08:49:11 -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=1c3EbDFH; 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 S1349785AbiFMK60 (ORCPT + 99 others); Mon, 13 Jun 2022 06:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350090AbiFMKyl (ORCPT ); Mon, 13 Jun 2022 06:54:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6EFD2496F; Mon, 13 Jun 2022 03:29:08 -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 67C7CB80E2D; Mon, 13 Jun 2022 10:29:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD01CC3411C; Mon, 13 Jun 2022 10:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116146; bh=4tvL/uObB8oELHOKTh9in7xifhIumfAmb8eA+LaNlpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1c3EbDFHYd0LtnpGYsE63eFatxxUBCTGr6HAHivJhKOF5B5D98leX1YlCpYDPiiPB 5qw15qTtLx5/sN1TcbIZaQ1wXjht59i0OP9vGS64XZGF0Gjlxut7SUXwgPfLOXbc34 aBAI3pRe7jvg3BH4yRg0LKUd3SdqI8hUKtTHigt8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steven Price , Liviu Dudau , Sasha Levin Subject: [PATCH 5.4 032/411] drm/plane: Move range check for format_count earlier Date: Mon, 13 Jun 2022 12:05:05 +0200 Message-Id: <20220613094929.467905153@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 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: Steven Price [ Upstream commit 4b674dd69701c2e22e8e7770c1706a69f3b17269 ] While the check for format_count > 64 in __drm_universal_plane_init() shouldn't be hit (it's a WARN_ON), in its current position it will then leak the plane->format_types array and fail to call drm_mode_object_unregister() leaking the modeset identifier. Move it to the start of the function to avoid allocating those resources in the first place. Signed-off-by: Steven Price Signed-off-by: Liviu Dudau Link: https://lore.kernel.org/dri-devel/20211203102815.38624-1-steven.price@arm.com/ Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_plane.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index d6ad60ab0d38..6bdebcca5690 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -186,6 +186,13 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, if (WARN_ON(config->num_total_plane >= 32)) return -EINVAL; + /* + * First driver to need more than 64 formats needs to fix this. Each + * format is encoded as a bit and the current code only supports a u64. + */ + if (WARN_ON(format_count > 64)) + return -EINVAL; + WARN_ON(drm_drv_uses_atomic_modeset(dev) && (!funcs->atomic_destroy_state || !funcs->atomic_duplicate_state)); @@ -207,13 +214,6 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, return -ENOMEM; } - /* - * First driver to need more than 64 formats needs to fix this. Each - * format is encoded as a bit and the current code only supports a u64. - */ - if (WARN_ON(format_count > 64)) - return -EINVAL; - if (format_modifiers) { const uint64_t *temp_modifiers = format_modifiers; while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID) -- 2.35.1