Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3960371ioo; Mon, 30 May 2022 14:09:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdxNQvkjrcgVBjrrhtDbjuhnmgiYCZz+173UBghdo8X5y2cLF8VB6QTo1DuUD87HRnBpcy X-Received: by 2002:aa7:d2cf:0:b0:42a:c1b1:9d6b with SMTP id k15-20020aa7d2cf000000b0042ac1b19d6bmr61691919edr.405.1653944968322; Mon, 30 May 2022 14:09:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653944968; cv=none; d=google.com; s=arc-20160816; b=rKCi0Yx/0zNc8oOLd1Ku7crEuwGwKHa0zQ2z7G+YZlvzMId13hXo2jB86LTJDFx3IP 3ZqGxyOLJVAJ+ZW/USGX8+nCywcjyxVceiiCR4O+d5DoASDh5ehjFSHVc0f6yGsxL8nV qvrqvvas6TVt8U5s99Uh7oMvFQc/NKhWlN4EY+2YmoEFET1XpZrk81oYusmiW3HMb5xJ WHL8ImLv0kdg18ZHQWLotfzd7TQnEmg3HK7Iz69qFDJwgQso+gF+YjeO1Efx+4Aypel0 9wxyO2XXI3/qjpSNfWqZiLHtBBhZhekc0CQ29GRn4l0TiCaxwKSWcvgi5vxyTUVkfPzD +cZA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1hBnCeIGPGDXYfmXfnAN59Y1kgSM3DIodRtbZsmkZzg=; b=t4huYYd6fUP6q+X8Kr1W8S/RW5OFB4QsiqNUWdeeOyiluh2Vw3SqpdjvevFQuKvidK 9NhtySbh454D7MVmPaZfRsS5ge0LScHHAa2r/uOc80O2flbQB7rPMW7Z9WAt7v2+/Q+q Xde05UJS91+iTHKeH66FP+InRY5D9eXsFawnY+Rc3aFwPY/mnMW+MLx74WT5OvThoFiK 00cSxW5u3oFbPkAZXm8KTQZDK0HifuqMgs9PSkov/GNlIfeBLI/zuq3oIt9maKy+IzEj A7BkXPqRUnHPFOcFwQf42MO4QFCUTkMVgwyGlm1R551poBwC+81Hd15fS2isOEK5+SP1 ZPrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F50vHFjV; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw40-20020a1709066a2800b006f39e0cbe8esi13726544ejc.227.2022.05.30.14.09.02; Mon, 30 May 2022 14:09:28 -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=@kernel.org header.s=k20201202 header.b=F50vHFjV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241937AbiE3Oas (ORCPT + 99 others); Mon, 30 May 2022 10:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241721AbiE3OSA (ORCPT ); Mon, 30 May 2022 10:18:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0298E7B9E0; Mon, 30 May 2022 06:48:00 -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 dfw.source.kernel.org (Postfix) with ESMTPS id DBC7460F24; Mon, 30 May 2022 13:47:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0241EC3411A; Mon, 30 May 2022 13:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918479; bh=4tvL/uObB8oELHOKTh9in7xifhIumfAmb8eA+LaNlpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F50vHFjVCwUXDCoJK2FgPIkyhMJK9dX9mj0DK+VpRO/KOlUhbrNDv8fGq7Sr0qWCy R6q6UCKWec9Cx3uS/g2aQT6ftbhwOXwZW4kc0bGp5aCjqsMR2vlaIkKyybfThn4EKX I94Sv+k1CiquoTCJi5UKUGFQ+k6s1kvB7CtRYiw3PThxkcEARNCGLEbRvJAmLlXH3h mdd/NAFzypk1wGSsf+ocCCgdXcpgO99cqZRjIOJdMsrniSNPkNAgtwYgeKuP4Cf1MQ 8U3cfMMHHLrCGJiELFfJkT8Bystvwbf8a+jN1x6EQWe9bE6Av7T2MrPbumFXidy/HS 4KLj0x4k+L8og== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Steven Price , Liviu Dudau , Sasha Levin , maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.4 23/55] drm/plane: Move range check for format_count earlier Date: Mon, 30 May 2022 09:46:29 -0400 Message-Id: <20220530134701.1935933-23-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530134701.1935933-1-sashal@kernel.org> References: <20220530134701.1935933-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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