Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1474738rwj; Sun, 18 Dec 2022 08:54:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4x5mdTh158hC1aHeAoHnqSdOjzZvXQtj9iMpqwKURh0g7eY/0b1JzLfVgqhKXjp6xL0izC X-Received: by 2002:a17:906:6d8e:b0:7ad:b6d8:c9d0 with SMTP id h14-20020a1709066d8e00b007adb6d8c9d0mr31697912ejt.53.1671382496487; Sun, 18 Dec 2022 08:54:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671382496; cv=none; d=google.com; s=arc-20160816; b=z02z4KCvZ7jch5jWrDu3H/Hb0saZjjnaNBxWePj4jNUZlXXqAR8P7SPUURz6jjKyya v2Lc0PqUxMhreIu3SU0GJvdbB85xg80HyLdQqAZScUDM+j0ofr8szZF+p4VAYj7cWdne /icv2qiKLliCOZqKjKEMEyiHNvlkVKLptkECVj0TlcEx29SFVBygUVqSJRYMRL5njMzM TwieZ/ZkXizeWE02gsjIzt4qCAzMBUl1G5leWWTAAFixPtWD+e0M8XXMVgy5YBYFfy76 1UCPzYCafzXZ8yCUCuITKN2mBs958DE8DMk/jaxmNCcNEhoA3Xc/2mK0P4fhTinnCxnW Ma+g== 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=kJCw1rJcWUUJKXHdB2YLSFy8th+LA3p0XIOZIzOhXhQ=; b=XmZBw+HQbE2aGFcKWPFlDLhZt22lzwQV7wjw4aR17f2phbnrZoF6mA7lv4pWQqtvcz VpnQGC2LLKPm/6a7wCl16bJXlm/q72qxW+Xjk0SDnmnteVWwBXu+J4rCbfZ9G2PwTv2C NohNHTAS0axQ5WTMPRy33qFMsNAtJCX5tMv4yvqbLrfxLTajgyLaUQCXZtci5JukaW1v wS6tCu9Gn0t7OIkte8pxlWrkK56P9T7+pTwuZuYB/DR19gveVEHMICcSWxvtOXFxe//5 GZqfEZl6/kEscyjBqADh5VGNmT00iPu1qSMtgmJ6jMitv3zJCBYdC3LbEXdmpbO3wuUv zzfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cDTHbTmg; 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 n15-20020aa7c44f000000b00461c50013b8si6603236edr.192.2022.12.18.08.54.40; Sun, 18 Dec 2022 08:54:56 -0800 (PST) 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=cDTHbTmg; 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 S232489AbiLRQln (ORCPT + 70 others); Sun, 18 Dec 2022 11:41:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbiLRQkh (ORCPT ); Sun, 18 Dec 2022 11:40:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 102808FED; Sun, 18 Dec 2022 08:14:23 -0800 (PST) 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 6A93E60DC8; Sun, 18 Dec 2022 16:14:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 083F4C433EF; Sun, 18 Dec 2022 16:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380059; bh=3pFuYycp5XaySMSnYBC9uKdZny+VGlfNZ0G0lpWOGrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDTHbTmgbBqZsrw1LlPmUiiE0xgFCDMDqDPh2oPEE3pdcYn4PEQUKjJtEqg8rQ1Ru qRQKWpiUhy7b3FwEg5tW/TSajdDMc7YOJintgxLmIm1QbxOPnowTO2TgGYV+O6EO95 7K8Av9K4E6IWwAtwD2TmHHakMZ4E/VX+4MBlAo2iKWgqLaZmQxuV7ctACIp8eMvm2B v7EY4Wyt3bSrpqsAFKcA5lDIsV9giZku1b9yO5NCa7h5LkE4Fg5/QLCj+uxn9C+ak1 Fk2QkQhk01s3I5EAmROCKihbAuls3Q92JW8ycyEKjcNPg/YkjyShwYENTdRDMDJv1x 7qIdTI1HIwmJw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Rob Clark , Sean Paul , Abhinav Kumar , linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Dmitry Baryshkov , Daniel Vetter , Sasha Levin , airlied@gmail.com, daniel@ffwll.ch, swboyd@chromium.org, quic_khsieh@quicinc.com, quic_sbillaka@quicinc.com, johan+linaro@kernel.org, andersson@kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.15 21/46] drm/msm: Use drm_mode_copy() Date: Sun, 18 Dec 2022 11:12:19 -0500 Message-Id: <20221218161244.930785-21-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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: Ville Syrjälä [ Upstream commit b2a1c5ca50db22b3677676dd5bad5f6092429acf ] struct drm_display_mode embeds a list head, so overwriting the full struct with another one will corrupt the list (if the destination mode is on a list). Use drm_mode_copy() instead which explicitly preserves the list head of the destination mode. Even if we know the destination mode is not on any list using drm_mode_copy() seems decent as it sets a good example. Bad examples of not using it might eventually get copied into code where preserving the list head actually matters. Obviously one case not covered here is when the mode itself is embedded in a larger structure and the whole structure is copied. But if we are careful when copying into modes embedded in structures I think we can be a little more reassured that bogus list heads haven't been propagated in. @is_mode_copy@ @@ drm_mode_copy(...) { ... } @depends on !is_mode_copy@ struct drm_display_mode *mode; expression E, S; @@ ( - *mode = E + drm_mode_copy(mode, &E) | - memcpy(mode, E, S) + drm_mode_copy(mode, E) ) @depends on !is_mode_copy@ struct drm_display_mode mode; expression E; @@ ( - mode = E + drm_mode_copy(&mode, &E) | - memcpy(&mode, E, S) + drm_mode_copy(&mode, E) ) @@ struct drm_display_mode *mode; @@ - &*mode + mode Cc: Rob Clark Cc: Sean Paul Cc: Abhinav Kumar Cc: linux-arm-msm@vger.kernel.org Cc: freedreno@lists.freedesktop.org Reviewed-by: Dmitry Baryshkov Reviewed-by: Abhinav Kumar Reviewed-by: Daniel Vetter Signed-off-by: Ville Syrjälä Link: https://patchwork.freedesktop.org/patch/msgid/20221107192545.9896-5-ville.syrjala@linux.intel.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index d13fd39f05de..15e38ad7aefb 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -840,7 +840,7 @@ static int dp_display_set_mode(struct msm_dp *dp_display, dp = container_of(dp_display, struct dp_display_private, dp_display); - dp->panel->dp_mode.drm_mode = mode->drm_mode; + drm_mode_copy(&dp->panel->dp_mode.drm_mode, &mode->drm_mode); dp->panel->dp_mode.bpp = mode->bpp; dp->panel->dp_mode.capabilities = mode->capabilities; dp_panel_init_panel_info(dp->panel); -- 2.35.1