Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3856755rdh; Tue, 28 Nov 2023 05:53:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsa+5sdzXXKIvbMTr0SqxWPTeCPyKm6RnUv4UyxlwnUeJ6h1emYHU/1m44PjpdsQmIhJB2 X-Received: by 2002:a05:6830:1e86:b0:6d3:127b:6fba with SMTP id n6-20020a0568301e8600b006d3127b6fbamr16816290otr.9.1701179583210; Tue, 28 Nov 2023 05:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701179583; cv=none; d=google.com; s=arc-20160816; b=iFbS8uVI3QwgSA5zGjqXsQpXuB+PjsWTbqNBAwCQqLhgse0RCqlzbWciCL1G7okR18 f4N7m8/sWOxJqBCJNu+7408LALJv0Jc8yHJmHLI59PWtz9y0UYD/4a707sB3h72g96xo lKbKoTH67SijCev0LOqiwahuPr/gGragyMFIecbih0NicGok00c2ifg8VhgtAQV/bzI6 pQLz2NocgeyXHWU1s5Bxl7r9Nj1dbjAuWn0TVOmTQ1gW4+zXFOgActno9NAxzGb0TYrG bx1TbM9P3B/QSKOFB6t5QJMNdkteORiSZmox9ZIWDOZvicyYptud3L9uXwmGQYczowmp +NRA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Yu0hhFdoo9rc1lvCTLcRecXfzD94wpfo0JXrkp12Pbw=; fh=xEKiaWSSKsulIgZY/DnMJ20XukDND9DHf1uJSG/Mv8A=; b=tt0ouvlTT+1TEIN7Vjf5KcKJn5vuPWKCjV/9rbMZsx1uqFKoCMiP5r1Ba5YQyu+dVp 4kViYZelmuLkb9QaN/SgF8ASdVpOVJMXw8VUvygypZNB+dJiNsGxK+w9uQHykwI/RH4A DFGc3mT7SaS1JrOVoYQxmsoRA0VASNPWgiLQ2ijdf1awm2zMdw5MCXrND/2+LjUxXEI0 E4kK1AdlDisDJGxrNM8Sh7rlr9lE5E1A2XEHYKdkqxKDCRubgqxjlChXGYg+UGIcZ67p U7ihdY9d3ekA3eHclhilXdixoaNo5Pgsof1OZpIPQa3uZwLsx8gIedCkimkn4Xdt/icw LFuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HPGndlVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id g22-20020a63f416000000b005c2122e482csi12381628pgi.700.2023.11.28.05.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 05:53:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HPGndlVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5454C805E437; Tue, 28 Nov 2023 05:53:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344771AbjK1Ntb (ORCPT + 99 others); Tue, 28 Nov 2023 08:49:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344720AbjK1Nta (ORCPT ); Tue, 28 Nov 2023 08:49:30 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 982391BB; Tue, 28 Nov 2023 05:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701179376; x=1732715376; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=ho8ya67y0bcAC8iRE41B+MB3YSCUZNByqFAIWF4TZg8=; b=HPGndlVuHasbVuRsfz4yI9RO89sry5KLzLp2AkdsjazcIgwsgjFtzv6O oa1F/rZYDpgA04yo57DUT3vhQ5UucrlAk2jQuC772WTFjs1jA/RiqrhDt Ei1R0mWvvHeuJtQtn6OdGrlWa39/mycnacPbKL59QRq+wcHFn/ePFk8Be MWSaW6ZFPz5c4aENMcrB6Enov2Q64uC2m5jPB2em6et9RtSJvpSjkyx9C AmJ1JUb+Jsfr+vuLRgIK6wOOTzBi3J+Y+V/4u3fnKf2/BBeBE+hQe2IdJ g/SV5HFIp198uQO7G+sFzEf8hbWFxWx5M1pncDmtQD+k0by75r7ZxqE1/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="392676347" X-IronPort-AV: E=Sophos;i="6.04,233,1695711600"; d="scan'208";a="392676347" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2023 05:49:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="761938211" X-IronPort-AV: E=Sophos;i="6.04,233,1695711600"; d="scan'208";a="761938211" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orsmga007.jf.intel.com with SMTP; 28 Nov 2023 05:49:08 -0800 Received: by stinkbox (sSMTP sendmail emulation); Tue, 28 Nov 2023 15:49:08 +0200 Date: Tue, 28 Nov 2023 15:49:08 +0200 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: Maxime Ripard Cc: Jani Nikula , Thomas Zimmermann , Emma Anholt , Jonathan Corbet , linux-kernel@vger.kernel.org, Samuel Holland , Sandy Huang , Jernej Skrabec , linux-doc@vger.kernel.org, Hans Verkuil , linux-rockchip@lists.infradead.org, Chen-Yu Tsai , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v4 05/45] drm/connector: Check drm_connector_init pointers arguments Message-ID: References: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> <20231128-kms-hdmi-connector-state-v4-5-c7602158306e@kernel.org> <87h6l66nth.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Patchwork-Hint: comment X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 05:53:00 -0800 (PST) On Tue, Nov 28, 2023 at 02:29:40PM +0100, Maxime Ripard wrote: > Hi Jani, > > On Tue, Nov 28, 2023 at 02:54:02PM +0200, Jani Nikula wrote: > > On Tue, 28 Nov 2023, Maxime Ripard wrote: > > > All the drm_connector_init variants take at least a pointer to the > > > device, connector and hooks implementation. > > > > > > However, none of them check their value before dereferencing those > > > pointers which can lead to a NULL-pointer dereference if the author > > > isn't careful. > > > > Arguably oopsing on the spot is preferrable when this can't be caused by > > user input. It's always a mistake that should be caught early during > > development. > > > > Not everyone checks the return value of drm_connector_init and friends, > > so those cases will lead to more mysterious bugs later. And probably > > oopses as well. > > So maybe we can do both then, with something like > > if (WARN_ON(!dev)) > return -EINVAL > > if (drm_WARN_ON(dev, !connector || !funcs)) > return -EINVAL; > > I'd still like to check for this, so we can have proper testing, and we > already check for those pointers in some places (like funcs in > drm_connector_init), so if we don't cover everything we're inconsistent. People will invariably cargo-cult this kind of stuff absolutely everywhere and then all your functions will have tons of dead code to check their arguments. I'd prefer not to go there usually. Should we perhaps start to use the (arguably hideous) - void f(struct foo *bar) + void f(struct foo bar[static 1]) syntax to tell the compiler we don't accept NULL pointers? Hmm. Apparently that has the same problem as using any other kind of array syntax in the prototype. That is, the compiler demands to know the definition of 'struct foo' even though we're passing in effectively a pointer. Sigh. -- Ville Syrj?l? Intel