Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2192445iof; Tue, 7 Jun 2022 22:45:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/gJBd5SC7rZWjosZ3Y48lOhRAsghvdxlj6RrE1cozmWFUMih8DCgWVg+ajzjuPPlIUHrE X-Received: by 2002:a17:902:9882:b0:167:5c8c:1ad with SMTP id s2-20020a170902988200b001675c8c01admr21760318plp.130.1654667104094; Tue, 07 Jun 2022 22:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667104; cv=none; d=google.com; s=arc-20160816; b=sfgzu4FxDuNUhPGoClB1a2xXAtA3rH+VJmXFN6otdI+MWxakqa2D5yDJtHlKWq0IJB P9jH4sJuRRZMuhast936vSCpvEpxvpF3zeG2InCZgWyKYepKQYUOMtZ96C/JRey5rHXw s772XcrTwmOQJJQLNq1g+FxFGMMShYLraq8S5bE4MMR4MIn1hpIbHQQIn5W3ezJJM+fA COV/GrpyaDryC976oIkYnQG3Ecpu+b8TBLhdi67xEFBh56Ge3jYVqQBojb91E5vrG9BI yviXuka3f7LUTw6PEPaIY5rR55NIcD/h7QkRJzYw27qFqRNsz1RHgBXhhDA2GE3sw6qY h0UA== 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=FhbBo8FCbg2aCb3lSNBF4xddESVJ0iR83tp2GhQVKgI=; b=yiN9ew7LKlWrVpXK9pF9+y8si1tCDrWgQRz7KBv432YZNsA2+4CFHAJ9QCyV2v1lAE nf34EtfkhcwbiPIY33XT7J+DWKfZyav6COBMA7OmI9EZtCEVEmL2h/V0zjl4z94A9C+E oe7NlyyLmSIhIQPSl6QM+pRCi28iLwesTnOM9eHX4ULhDbhzdriWIGipd8tJ1ofpyX9i lrKlpRMz0GzF8sIhl8AbFCnDj+tOMrYOQ0pZA0ytEOiQBFt2fh3POgSU/N9G4bTDWCI7 hVpqbnMHFTvlzl05v1vMWwR6ryceowOj5yttRNz7iy/wifxYgsQ8sBwzpoL+dCk51P/S KLSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmDtuPpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v186-20020a6389c3000000b003fa936eedd8si26964578pgd.481.2022.06.07.22.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:45:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmDtuPpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25E6D474C3C; Tue, 7 Jun 2022 22:09:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353118AbiFHAS5 (ORCPT + 99 others); Tue, 7 Jun 2022 20:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383480AbiFGWa6 (ORCPT ); Tue, 7 Jun 2022 18:30:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DD627622D; Tue, 7 Jun 2022 12:24:10 -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 BF08C60BA3; Tue, 7 Jun 2022 19:24:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA5A9C385A2; Tue, 7 Jun 2022 19:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629849; bh=I01p0vfEEMyUzbTAF3PuxHt9/dUVilVk+CUtI2t2RoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmDtuPpbcPuIZD1eqjZpjD7PZ/unN1FS+CepjAb2k8nhl3Ujp+y/J3uUJjmYhMZ6C N0kl32Sem2KaF/Pa169uz2tQw9WNprBLGIdoR8D0/aVJT3CEQdGiELPUESxBoNG7LC YehftGhlaKQCUR84s7MAwUGvfDdGFQGIik4XCsbM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , Raphael Gallais-Pou , Philippe Cornu Subject: [PATCH 5.18 838/879] stm: ltdc: fix two incorrect NULL checks on list iterator Date: Tue, 7 Jun 2022 19:05:56 +0200 Message-Id: <20220607165027.178600320@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Xiaomeng Tong commit 2e6c86be0e57079d1fb6c7c7e5423db096d0548a upstream. The two bugs are here: if (encoder) { if (bridge && bridge->timings) The list iterator value 'encoder/bridge' will *always* be set and non-NULL by drm_for_each_encoder()/list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found. To fix the bug, use a new variable '*_iter' as the list iterator, while use the old variable 'encoder/bridge' as a dedicated pointer to point to the found element. Cc: stable@vger.kernel.org Fixes: 99e360442f223 ("drm/stm: Fix bus_flags handling") Signed-off-by: Xiaomeng Tong Acked-by: Raphael Gallais-Pou Signed-off-by: Philippe Cornu Link: https://patchwork.freedesktop.org/patch/msgid/20220327055355.3808-1-xiam0nd.tong@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/stm/ltdc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -869,8 +869,8 @@ static void ltdc_crtc_mode_set_nofb(stru struct drm_device *ddev = crtc->dev; struct drm_connector_list_iter iter; struct drm_connector *connector = NULL; - struct drm_encoder *encoder = NULL; - struct drm_bridge *bridge = NULL; + struct drm_encoder *encoder = NULL, *en_iter; + struct drm_bridge *bridge = NULL, *br_iter; struct drm_display_mode *mode = &crtc->state->adjusted_mode; u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h; u32 total_width, total_height; @@ -880,15 +880,19 @@ static void ltdc_crtc_mode_set_nofb(stru int ret; /* get encoder from crtc */ - drm_for_each_encoder(encoder, ddev) - if (encoder->crtc == crtc) + drm_for_each_encoder(en_iter, ddev) + if (en_iter->crtc == crtc) { + encoder = en_iter; break; + } if (encoder) { /* get bridge from encoder */ - list_for_each_entry(bridge, &encoder->bridge_chain, chain_node) - if (bridge->encoder == encoder) + list_for_each_entry(br_iter, &encoder->bridge_chain, chain_node) + if (br_iter->encoder == encoder) { + bridge = br_iter; break; + } /* Get the connector from encoder */ drm_connector_list_iter_begin(ddev, &iter);