Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9737884ybi; Wed, 10 Jul 2019 16:05:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwd7DbHIwzqTMB7Fm93Z2Wy62jJ1lzzDsdZq1W11TZUgbJgUrI8t8C9sBMp0OjkWGaZGNnx X-Received: by 2002:a65:50c5:: with SMTP id s5mr797742pgp.368.1562799925176; Wed, 10 Jul 2019 16:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562799925; cv=none; d=google.com; s=arc-20160816; b=WM78tNowQjL9WrMmHDHAdAO/Ihdo9hsaoJP3H9xYyMJMgUwhKANv1yCFkCZNmQnmab PE7ZnUgg6UWSYAgcPUjcVgWyoCzAHbAGJ04LKSEveQ77UVXZfF96gVv/Ta122HKWxwZA kzACOqW/6SGuhQMVpJJsq6TT/0BOk6zYxNFQo5RDS9QBGHymZO6PbZ6805Hyx5A1d3pI XCADzstDUOHMOk7Zb+SUa/4hnWeRXDR2lJv3Dx/v4lNXO/1A/zSDj/5Vyh9Q1B+TG3Rp grBMFL89GzOXwu8qFwx5K+COi/P46oCVr5E++UjrgClllHNzrQJy3j0HpwIxIBS4+Uf+ /xrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=h1QrIpFdh5rLkTKFlCHaduUWYuYcrWpgjVEeSTaTyVo=; b=ITO72Bl96nemMKlqItMB/5UcqvHUubSVXR+3B6g+JrQtwtHwKtOQoe/Qqs8bZ0uFoC sYtiEBb1USkXXFSFwOKWIC7NT5B99OTrVcF8xPZXZxRJ7uTW3Kme6ihRleCUBSRlvi9j v+uNH+dNM29e27G5hmEGXvPYREp4+6kReN33adLq7vTxF/sooP2Gu1M/ewtuenw6UXOL eT76/bUebNuWJMKksS+lWRo3jLs7EGvK7XxJSUgRYRQssrv3NZIQn5UBytIyDSjjDOx5 5AUOrVlfvRxndlxgNJ1IBh73epqN6zKk2+Ml+8a6i6Zi13L+a9b0kdMDSZqhMVEnYJa+ SkjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i5KPrHov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be11si2955276plb.218.2019.07.10.16.05.07; Wed, 10 Jul 2019 16:05:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i5KPrHov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727345AbfGJWkK (ORCPT + 99 others); Wed, 10 Jul 2019 18:40:10 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:39322 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfGJWkJ (ORCPT ); Wed, 10 Jul 2019 18:40:09 -0400 Received: by mail-io1-f67.google.com with SMTP id f4so8308368ioh.6 for ; Wed, 10 Jul 2019 15:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h1QrIpFdh5rLkTKFlCHaduUWYuYcrWpgjVEeSTaTyVo=; b=i5KPrHovfkqkwkajM2OJwC/MI8IVo3lIvSf1xBkUaMHWuUyWkij1QldVl9kX/GMlE1 DNsrFiTH/7r6LswYJlPb1030krcbMTp9icHuWypgydw+2C+kuV72UBpH6KFLdct9hP6R bfQOoNSN7axemJnh/3RbdCrrYZ6IDuOtjaP+w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h1QrIpFdh5rLkTKFlCHaduUWYuYcrWpgjVEeSTaTyVo=; b=ZNvv0FN3uz/4h+GpD7HcOttLF6dlR8/j8Edo7BXp+PWDpCslX/wHVItRSzarJaAVay hX69UWnmofLfO141wqVg5Apgtm7EXf9Wi5vB1WaD51YBdLOW9Vamg2R2yNs4TdFvN0QN 6HjEfLXjRJsYKaADWegdPZVKMH2TOTtwl59QKO3bVamnACyuG0hTiYyZqXylSpAiIBoa yHCts3G3D7oJu5293qDk4WRincB8k/A4MXYZTQgLB8g1lI/Z2mt4lyUv726w6k0rBd7x loUz0Hx3rlE+ugeFJ1xsqDQrB8nKuPkOX8SGY8wF8wBqBjFI2MPNSVNJPyUXBTTSws/o gqXQ== X-Gm-Message-State: APjAAAXMHyvIJDKC8cZNYFq4IKKGsEXmro0W3RPplKhHIMyyJM3TfNub 8m9vhA0k79xqhqjOQ3BCO9wm8SAX0cw= X-Received: by 2002:a6b:8f47:: with SMTP id r68mr646937iod.204.1562798408520; Wed, 10 Jul 2019 15:40:08 -0700 (PDT) Received: from mail-io1-f50.google.com (mail-io1-f50.google.com. [209.85.166.50]) by smtp.gmail.com with ESMTPSA id m25sm2008841ion.35.2019.07.10.15.40.05 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 15:40:05 -0700 (PDT) Received: by mail-io1-f50.google.com with SMTP id o9so8347837iom.3 for ; Wed, 10 Jul 2019 15:40:05 -0700 (PDT) X-Received: by 2002:a02:c6a9:: with SMTP id o9mr688304jan.90.1562798405041; Wed, 10 Jul 2019 15:40:05 -0700 (PDT) MIME-Version: 1.0 References: <20190401171724.215780-1-dianders@chromium.org> <20190401171724.215780-3-dianders@chromium.org> <20190630202246.GB15102@ravnborg.org> <20190708175007.GA3511@ravnborg.org> In-Reply-To: <20190708175007.GA3511@ravnborg.org> From: Doug Anderson Date: Wed, 10 Jul 2019 15:39:52 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 2/7] drm/panel: simple: Add ability to override typical timing To: Sam Ravnborg Cc: Thierry Reding , Heiko Stuebner , Sean Paul , devicetree@vger.kernel.org, Rob Herring , David Airlie , Jeffy Chen , dri-devel , LKML , "open list:ARM/Rockchip SoC..." , Boris Brezillon , Laurent Pinchart , =?UTF-8?Q?Enric_Balletb=C3=B2?= , =?UTF-8?Q?St=C3=A9phane_Marchesin?= , Ezequiel Garcia , Matthias Kaehlcke Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sam, On Mon, Jul 8, 2019 at 10:50 AM Sam Ravnborg wrote: > > Hi Dough. > > On Mon, Jul 01, 2019 at 09:39:24AM -0700, Doug Anderson wrote: > > Hi, > > > > On Sun, Jun 30, 2019 at 1:22 PM Sam Ravnborg wrote: > > > > > > > @@ -91,6 +92,8 @@ struct panel_simple { > > > > struct i2c_adapter *ddc; > > > > > > > > struct gpio_desc *enable_gpio; > > > > + > > > > + struct drm_display_mode override_mode; > > > I fail to see where this poiter is assigned. > > > > In panel_simple_parse_override_mode(). Specifically: > > > > drm_display_mode_from_videomode(&vm, &panel->override_mode); > > The above code-snippet is only called in the panel has specified display > timings using display_timings - it is not called when display_mode is > used. > So override_mode is only assigned in some cases and not all cases. > This needs to be fixed so we do not reference override_mode unless > it is set. I'm afraid I'm not following you here. * override_mode is a structure that's directly part of "struct panel_simple". * The panel is allocated in panel_simple_probe() with devm_kzalloc(). * The "z" in kzalloc means that this memory will be zero-initialized. From the points above, "override_mode" will always be set to something. If we didn't run "drm_display_mode_from_videomode(&vm, &panel->override_mode);" then we know the entire override_mode structure will be zero. While it took a while for me to get used to it, the kernel convention is to rely on zero-initialization and not to explicitly init things to zero. As an example of this being codified in the source, you can see that "checkpatch.pl" will yell at you for a similar thing: "do not initialise globals to 0". > > > @@ -152,6 +162,44 @@ static int panel_simple_get_fixed_modes(struct panel_simple *panel) > > > > num++; > > > > } > > > > > > > > + return num; > > > > +} > > > > + > > > > +static int panel_simple_get_non_edid_modes(struct panel_simple *panel) > > > > +{ > > > > + struct drm_connector *connector = panel->base.connector; > > > > + struct drm_device *drm = panel->base.drm; > > > > + struct drm_display_mode *mode; > > > > + bool has_override = panel->override_mode.type; > > > This looks suspicious. > > > panel->override_mode.type is an unsigned int that may have a number of > > > bits set. > > > So the above code implicitly convert a .type != 0 to a true. > > > This can be expressed in a much more reader friendly way. > > > > You would suggest that I add a boolean field to a structure to > > indicate whether an override mode is present? > A simple bool has_override = panel->override_mode.type != 0; > would do the trick here. > Then there is no hidden conversion from int to a bool. I will change this to "panel->override_mode.type != 0" if you're really sure, but this seems both against the general Linux style feedback I've received over the years (though there is definitely not 100% consistency) and also against the local convention in this file. Examples in this file of treating ints as bools without an explicit "!= 0": * panel_simple_get_fixed_modes checks "if (panel->desc->bus_format)" * panel_simple_disable checks "if (p->desc->delay.disable)" * panel_simple_unprepare checks "if (p->desc->delay.unprepare)" * panel_simple_prepare checks "if (delay)" * panel_simple_enable checks "if (p->desc->delay.enable)" ...and, although slightly different, pointers in this file are checked for NULL vs. non-NULL without an explicit "== NULL". Of course just because all the other examples in the file do it one way doesn't mean that new code has to do it another way, but I wanted to be really sure you wanted me to go against the existing convention before changing this. > But as override_mode can be NULL something more needs to be done. I'm afraid I don't understand how override_mode can be NULL since it's not a pointer. Can you clarify? -Doug