Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp405567rwi; Thu, 27 Oct 2022 02:59:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Ngd3Orm6uJbMgg5QZta/hf0FZQ7ukq8FqH7okNGmFiDq3bti4fo5VXYPPoXiDnEL1AWqN X-Received: by 2002:a17:906:8a4b:b0:7a7:3e17:7f91 with SMTP id gx11-20020a1709068a4b00b007a73e177f91mr19288140ejc.331.1666864753351; Thu, 27 Oct 2022 02:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666864753; cv=none; d=google.com; s=arc-20160816; b=ibKt0LG9Af5B5BIlgRbCBuFImszm76UYEWDAOt1HMoy51gRIXFKQN/BusZdLyfNiJu ExuCmAPb+B09Mk84MgR4sN0ecXqVaH6WxNYuGS6utrmR4RO1hyi0RaOWqO36vvu151bQ RYbOVi2uhY2RgshH1Sl20x+ACpu5jJnm7CckbR+aDapRfrgUXL70RKeQjVh7lRsiUT1e cncxgoR7ah+S3LLXO2tTWWdKhDo/fAe27zg6zMJKslOuXCvJDlYI53zDUJv0n+7o6r9F cPAuBBPN6pMN6TWcx2errNrE5UcNGBD4yqm6KAC9Va/j2xP3WHBH25rvruYQkX98CwGD 4uMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=5ItCVshj6JyZau2J5cjH0M8JHw139GrYlnIerAQcZWs=; b=f3EcIw10T3ljVgVNOja+i2s6T/HZ3fLVuDAb7ZV6CSqeiCsRHT8WeTS7rO+ncv28il RsFwPXHIsR6uhKH3WBRGrqOUYGZalxl4wDPMxyS20Q2KZ8EBH6Xrn1pcqwB8NV7roNzn 8BvNYppSxWBaEbzudiOuu2DKABFofIDTFQ6IoNiSqENak+qhNNuk6NEVGaRB3bMjqJIV KdA3xtomOIYsu0lzmEPV6RXK9bk7Da1D7l08Oqh8yH3RArWpylpN3pEWKm/F4svrecqw f5L2DHA11DDXJju6aBHrRupEJCLM9cdREr7FjS32qEf1X6QHdjKk/UDjbvxGo4WqzllZ MpWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=IVFSYrra; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=aMBp3hE4; 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=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n26-20020a5099da000000b00461e63fe88fsi885314edb.596.2022.10.27.02.58.48; Thu, 27 Oct 2022 02:59:13 -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=@cerno.tech header.s=fm3 header.b=IVFSYrra; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=aMBp3hE4; 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=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234425AbiJ0Jhs (ORCPT + 99 others); Thu, 27 Oct 2022 05:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233626AbiJ0Jhn (ORCPT ); Thu, 27 Oct 2022 05:37:43 -0400 Received: from wnew1-smtp.messagingengine.com (wnew1-smtp.messagingengine.com [64.147.123.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E8577EBC for ; Thu, 27 Oct 2022 02:37:41 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.west.internal (Postfix) with ESMTP id E0A312B066EB; Thu, 27 Oct 2022 05:37:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 27 Oct 2022 05:37:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1666863454; x=1666870654; bh=5ItCVshj6J yZau2J5cjH0M8JHw139GrYlnIerAQcZWs=; b=IVFSYrra2yRKDBScb6i+EPPsnR H7iUD7VkPJAKE695dyeIFHVvDzTnEOFd/PuRkXJYQDLL3GqO5VDnC18zyG53l/7I pvgnmLqeiBPBWXQjApcUVHOrKRHilbj5+ASZsv6ndq61A0vf5cAG6GPGNStKiCRy wer2bctGBN1o9JRLtzfw8j3SxBth2GhmC1AF3SbqCoOAk5ikvGienxjeMuTVnd3b CIYEdhLoJTnMe4apOVtrct3AJygLwtX9QefTOEjFMks85VRv9W7SGo+EMXE4ei+c /vSdG+pF0qpFn1D0F3ffTOrvCiLzPaO3Iv99pS2pxcK/5ssmEIuPwA72joMw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1666863454; x=1666870654; bh=5ItCVshj6JyZau2J5cjH0M8JHw13 9GrYlnIerAQcZWs=; b=aMBp3hE4BgyODOr6WOBsdolHjS2Onrihiev6Ff/sAjQh Cama2t5zFVnEKp63jv9ugJbpKhvl71qc+L5qSL1TZPihHUka8luZ1042BOHS5Sxh aMKHX7Ay1bGb29oD5v8DX8oZBPKSAoX9G4RJblIy3UNVtu3bbfNqg1CYVaEHxNJc pHr9LW/SlL0Xhx1KndHWOx5hpeWVSz48zu40JY3Je6zDtTTEvFuI+nyPVFLcWWtY eqbDGYXUYbYyBSfExtphfrsas5tR+XzSbiwxPrJVDiXhOZHeBFTCAEXgpwFpx+Y+ pod1LrzbN+UsFQjTvFLBJJEhMjbUc60CIEflbK3G1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrtdeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepteefffefgfektdefgfeludfgtdejfeejvddttdekteeiffejvdfgheehfffh vedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmh grgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 27 Oct 2022 05:37:32 -0400 (EDT) Date: Thu, 27 Oct 2022 11:37:30 +0200 From: Maxime Ripard To: Mateusz Kwiatkowski Cc: Karol Herbst , Emma Anholt , Ben Skeggs , Chen-Yu Tsai , Rodrigo Vivi , Maarten Lankhorst , Jani Nikula , Daniel Vetter , Thomas Zimmermann , Tvrtko Ursulin , Samuel Holland , Jernej Skrabec , David Airlie , Joonas Lahtinen , Lyude Paul , linux-sunxi@lists.linux.dev, intel-gfx@lists.freedesktop.org, Phil Elwell , linux-arm-kernel@lists.infradead.org, nouveau@lists.freedesktop.org, Hans de Goede , Dom Cobley , dri-devel@lists.freedesktop.org, Dave Stevenson , linux-kernel@vger.kernel.org, Noralf =?utf-8?Q?Tr=C3=B8nnes?= , Geert Uytterhoeven Subject: Re: [PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper Message-ID: <20221027093730.tb4oaissdapf6ifr@houat> References: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech> <20220728-rpi-analog-tv-properties-v6-16-e7792734108f@cerno.tech> <8d0eee22-50f5-5b0a-c1e6-c5f61dd5bbcd@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="xamrv4lbhqfdsxuo" Content-Disposition: inline In-Reply-To: <8d0eee22-50f5-5b0a-c1e6-c5f61dd5bbcd@gmail.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, 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 --xamrv4lbhqfdsxuo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Mateusz, On Thu, Oct 27, 2022 at 12:02:24AM +0200, Mateusz Kwiatkowski wrote: > First of all, nice idea with the helper function that can be reused by > different drivers. This is neat! Yeah, it looked to me that given how complex it is, we don't want to duplicate it in each and every driver. > But looking at this function, it feels a bit overcomplicated. You're > creating the two modes, If reported as supported by the connector, yes. > then checking which one is the default, then set the preferred one and > possibly reorder them. Maybe it can be simplified somehow? Possibly, but I couldn't find something simpler. We should only expose the modes that the driver reports as supported, so we can have 0-2 modes. Then the preferred flag needs to be set on the default one like you suggested. But also, EDIDs define the preferred mode as either the mode with the flag set or the first mode listed. So a lot of program just use the heuristic to just pick the first mode listed. So it might be that I'm too careful, but it still seems useful to me. > Although when I tried to refactor it myself, I ended up with something th= at's > not better at all. Maybe it needs to be complicated, after all :( Yeah, that was my conclusion too :/ > Anyway, the current version seems to have a couple of bugs: >=20 > > + if (tv_mode_supported(connector, DRM_MODE_TV_MODE_PAL) || > > + tv_mode_supported(connector, DRM_MODE_TV_MODE_PAL_N) || > > + tv_mode_supported(connector, DRM_MODE_TV_MODE_SECAM)) { > > + mode =3D drm_mode_analog_pal_576i(connector->dev); > > + if (!mode) > > + return 0; > > + > > + tv_modes[count++] =3D mode; > > + } >=20 > If the 480i mode has been created properly, but there's an error creating= the > 576i one (we enter the if (!mode) clause), the 480i mode will leak. >=20 > > + if (count =3D=3D 1) { >=20 > You're handling the count =3D=3D 1 case specially, but if count =3D=3D 0,= the rest of > the code will assume that two modes exist and probably segfault in the pr= ocess. >=20 > > + ret =3D drm_object_property_get_default_value(&connector->base, > > + dev->mode_config.tv_mode_property, > > + &default_mode); > > + if (ret) > > + return 0; > > + > > + if (cmdline->tv_mode_specified) > > + default_mode =3D cmdline->tv_mode; >=20 > In case of an error (ret !=3D 0), the modes created so far in the tv_mode= s array > will leak. Thanks for the review, I'll fix these bugs > Also, I wonder if maybe the if (cmdline->tv_mode_specified) clause should= go > first? If we're going to use the default from cmdline, there's no point i= n even > querying the property default value. Maybe, I don't know. I find the flow of the code more readable that way, but if you disagree I'll change it. Maxime --xamrv4lbhqfdsxuo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCY1pRWgAKCRDj7w1vZxhR xTVQAQCdqQ7+vEr0O0pC7P93kHAYwFz0oBZn90Ip4EjyExKRPgD/cMwjjUZ6daWo /idlovksY5X1UdblxYiDcBffKZ9k8gM= =nRSG -----END PGP SIGNATURE----- --xamrv4lbhqfdsxuo--