Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp296476rwj; Thu, 22 Dec 2022 07:53:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsxDR6T8ONmRMhOzZiyw3cKLQbLgdVEFMtSv1IsyGRbM6XsQLS5t0xWHKw7RQlqONuah+e6 X-Received: by 2002:a50:d0d1:0:b0:478:be92:3384 with SMTP id g17-20020a50d0d1000000b00478be923384mr5841360edf.14.1671724405272; Thu, 22 Dec 2022 07:53:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671724405; cv=pass; d=google.com; s=arc-20160816; b=W60l79l+xWDNPg/0M6jbE52dRV7UkTQmBsLMOtOSG8UHjRxB8r+hDaYDQnrdTtN5in mer1XAcqgLj/XVyQg+LlJwsnE+gVHwlgyx93z613qv8bGm/6ZvzKNdCQGAcMKRU7ftoA FjKZ/5YrBhrEmZtXDiy04ygH8iDqV/Imf+KqZNaHFLYOFVHXhxGdesi6LXp+tTiVVmjH LLrHBoLoSk0t91+P7ViQ3OI3/x/UjB8Sy0aKUSjSVzOcZLVD3jGEfkq2rtIDiA4JHgM3 jt/1S0pWjRGHam5e1FVnmum4qmF1Hp/8Z9MuNtOEOf4pLYYiiVLadcXDZvrP8/XQO5nB pOwg== ARC-Message-Signature: i=2; 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:date:subject:message-id:cc:to:from :dkim-signature; bh=32++P+q6Vmnok5SXRBgj9sElDpHPxwJUSBDXcv+gGuA=; b=yhJfa9Dx96YhrIrlxS/N8ZLXHJA9g/TyxnHdmty2YEdyfJmHCfByzm6KXDEzibzrGZ 9Uar7mOUMAUBAWjQv4mnozziRY6Vvbr6CK5SqOQPhZr6RlIuuV0TacpE0EvW9qw5sX9T iz9N4lY3cD/PqqpwB5Vr79s9vyvs5VefU+P6ngirtqNDUlF/Mnz2TJbYlW5JfQS9wjLl zeAlHyNoQuUIAs7Hmr3nvVys5BQLDEGP0MEJ3lB3VvRaoHOy6ryJ5M7MdUN1stT5PoJr Jks6FCLLcHjQeMMW/YqlhPK/c1+RJHqQvnSJGTTsAw7vSpGDtmF0meM5r62h4THzHMHu f4Zg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=YJosYX+N; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f2-20020a05640214c200b0046dc78b47e9si840226edx.173.2022.12.22.07.53.09; Thu, 22 Dec 2022 07:53:25 -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=@siddh.me header.s=zmail header.b=YJosYX+N; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230178AbiLVPla (ORCPT + 67 others); Thu, 22 Dec 2022 10:41:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbiLVPl2 (ORCPT ); Thu, 22 Dec 2022 10:41:28 -0500 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF7911C19 for ; Thu, 22 Dec 2022 07:41:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671723650; cv=none; d=zohomail.in; s=zohoarc; b=VqvptbOUabuM1XNJN3E+8gBnGn7sCqG26D1Ws2ZYAfywGWAPwLDrNnVwC5/6dZBXcSfROHLfCyqJkV8Evm5qgSN5C/WRWCORKAF0fW+VbZs4p+WAF4X5/WQE6qLoWlCVZggVDXpD4OopQGPfpRuaXw9KzlwxPQne2RNsgO2ERCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1671723650; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=32++P+q6Vmnok5SXRBgj9sElDpHPxwJUSBDXcv+gGuA=; b=TY3CzIcESJuLY6p128Ubg8sToU5g3bI99MQtg/PL3+AqBIuRkN0cjQMT6RbmQabtvl3Mnj7snqi9Z+yYs9omkvYt9iFCYncyLwFV1DPy81tQF+3C18KpzBY5zm8mjMaWq7wt0H/TwINKPIIzfp4bm6w7W5DjoG1pXckSKBiQRL4= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1671723650; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=32++P+q6Vmnok5SXRBgj9sElDpHPxwJUSBDXcv+gGuA=; b=YJosYX+N3UI6pQO1AtjuwCz/NAevzV6UWbox/NlRJuB+DSxG44hHsXDy768ZGxIf Dt3X8DR+v9Vpt8uLpR9wp7nzpDEham7e/2fAIgVzoI/IfVAtgvzFq+csarRH7r8F/ah K3dTJZr1cD+6Q3nzeSSNcY6JPw8FEehHVouMSwcs= Received: from kampyooter.. (110.226.31.37 [110.226.31.37]) by mx.zoho.in with SMTPS id 1671723648363134.27341012227134; Thu, 22 Dec 2022 21:10:48 +0530 (IST) From: Siddh Raman Pant To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Simon Ser Cc: dri-devel , linux-kernel Message-ID: Subject: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument of drm_dbg_* Date: Thu, 22 Dec 2022 21:10:37 +0530 X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Comments say macros DRM_DEBUG_* are deprecated in favor of drm_dbg_*(NULL, ...), but they have broken support for it, as the macro will result in `(NULL) ? (NULL)->dev : NULL`. Thus, fix them by separating logic to get dev ptr in a new function, which will return the dev ptr if arg is not NULL. Use it in drm_dbg_*, and also in __DRM_DEFINE_DBG_RATELIMITED, where a similar (but correct) NULL check was in place. Signed-off-by: Siddh Raman Pant --- include/drm/drm_print.h | 42 ++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index a44fb7ef257f..6d2d5c522e25 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -34,6 +34,7 @@ #include =20 #include +#include =20 /* Do *not* use outside of drm_print.[ch]! */ extern unsigned long __drm_debug; @@ -451,6 +452,22 @@ void __drm_dev_dbg(struct _ddebug *desc, const struct = device *dev, * Prefer drm_device based logging over device or prink based logging. */ =20 +/** + * __drm_get_dev_ptr - Helper function to get device type pointer even if = NULL + *=09=09 is passed. Primarily for use in print macros, since they + *=09=09 need to handle NULL as the first argument passed. + * @drm: The *drm_device pointer, or NULL. + * + * RETURNS: + * The *device pointer, or NULL. + */ +static inline struct device *__drm_get_dev_ptr(const struct drm_device *dr= m) +{ +=09if (drm) +=09=09return drm->dev; +=09return NULL; +} + /* Helper for struct drm_device based logging. */ #define __drm_printk(drm, level, type, fmt, ...)=09=09=09\ =09dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__) @@ -487,25 +504,25 @@ void __drm_dev_dbg(struct _ddebug *desc, const struct= device *dev, =20 =20 #define drm_dbg_core(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__) -#define drm_dbg_driver(drm, fmt, ...)=09=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS_= _) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__) +#define drm_dbg_driver(drm, fmt, ...)=09=09=09=09=09\ +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_DRIVER, fmt, ##__VA_ARGS__) #define drm_dbg_kms(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_KMS, fmt, ##__VA_ARGS__) #define drm_dbg_prime(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__= ) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_PRIME, fmt, ##__VA_ARGS__) #define drm_dbg_atomic(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS_= _) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) #define drm_dbg_vbl(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_VBL, fmt, ##__VA_ARGS__) #define drm_dbg_state(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__= ) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_STATE, fmt, ##__VA_ARGS__) #define drm_dbg_lease(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__= ) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_LEASE, fmt, ##__VA_ARGS__) #define drm_dbg_dp(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_DP, fmt, ##__VA_ARGS__) #define drm_dbg_drmres(drm, fmt, ...)=09=09=09=09=09\ -=09drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS_= _) +=09drm_dev_dbg(__drm_get_dev_ptr(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__) =20 #define drm_dbg(drm, fmt, ...)=09drm_dbg_driver(drm, fmt, ##__VA_ARGS__) =20 @@ -596,10 +613,9 @@ void __drm_err(const char *format, ...); #define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...)=09=09=09=09= =09\ ({=09=09=09=09=09=09=09=09=09=09=09=09\ =09static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_= RATELIMIT_BURST);\ -=09const struct drm_device *drm_ =3D (drm);=09=09=09=09=09=09=09\ =09=09=09=09=09=09=09=09=09=09=09=09\ =09if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))=09=09= =09\ -=09=09drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARG= S__);=09\ +=09=09drm_dev_printk(__drm_get_dev_ptr(drm), KERN_DEBUG, fmt, ## __VA_ARGS= __);=09\ }) =20 #define drm_dbg_kms_ratelimited(drm, fmt, ...) \ --=20 2.35.1