Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7506145rwd; Tue, 6 Jun 2023 11:42:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dt7KTK1+m0bDFLRhJq8inQYRwGS+IXTr6E9Rjonn3tjpti5fIPkZnJFFpAnl4c3VCmNXX X-Received: by 2002:ac8:5f0b:0:b0:3f5:434c:3506 with SMTP id x11-20020ac85f0b000000b003f5434c3506mr730707qta.11.1686076938685; Tue, 06 Jun 2023 11:42:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686076938; cv=pass; d=google.com; s=arc-20160816; b=vW85nR3/aYKKf2ohw4J6DIOY/FMQdsVbIG+hay3SHiXQK7ncpSvaAIH9t9xKjOPOmJ LLSqBxZUu6v3iwbDGMkQDLd7G+8wFh9vbZgzZny8kovNUmtWd96CK6ckWXtD90z7QiuO 67khE0SiF86GmZ447xhDOUQ0BXwWr4YtyNvKB9CXPhOQmyyUdRYOAxmWAUBzYWTphAeC 91G/wuYcfA0nndzLbE4y8JVlgMGqX8uabXrAolQpvAIG5CbYPgp/A1seVZdPxne14C0Q cmK8sib/ZFP1vfmYB7r/j5n6mF5UVvNr8ax4Ce2rijuMWWLY+eG4ElzQpgFxl5H3JBFf DXHQ== 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=E3wsEOm0W4tH0/8fNIF9dAj0SXCaI/2HSNkzbMWF33M=; b=TEdhKwhQeX7nxxx1bp0F87gjmw9R4pCHD7B0rmAwQtWulLgR8xZNVOBceChHzWD+8F uk3UQbeGaGW+bS+7WKlP8sgXEfw4XxtA6iVT6LlEJYKBTRBhp6oSp2tn6XBFsbn/eLT7 DUqEwPB92mFO+KvciHVhrVeOJuNRsUMt5wl0AimVYr4p6Dcv0GTWToMLnsvxS7URzjG1 SLpn3qhi3KIpuyZX7ns+6vPCxbvjlxPixBYP04ZkVmXvCDlEM4moKM7E/rz2s6Vjm2O3 DG379j88Rl622shveL7+ZuqNNAIEPWe5JiJcxfSwIWGI8dFmsuo3fI/qLa+q08tFFUhY C1pg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=kT04OZUy; 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=NONE sp=NONE 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 w14-20020ac857ce000000b003f3e1e4d347si6796563qta.138.2023.06.06.11.42.03; Tue, 06 Jun 2023 11:42:18 -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=@siddh.me header.s=zmail header.b=kT04OZUy; 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=NONE sp=NONE dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238975AbjFFSbV (ORCPT + 99 others); Tue, 6 Jun 2023 14:31:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238791AbjFFSbM (ORCPT ); Tue, 6 Jun 2023 14:31:12 -0400 Received: from sender-of-o51.zoho.in (sender-of-o51.zoho.in [103.117.158.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179911706 for ; Tue, 6 Jun 2023 11:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686076228; cv=none; d=zohomail.in; s=zohoarc; b=Tno1bljdkHcYVc6K+67s1v9F18IfA0aJ74noJFJd+XRISspolsMlQFQpC9FFFVPu65dnQntpkbQcO+ZjRnwFHJihuYaHDmuLsY9HngaThOL8EYJEr/x5M/U/optSWoe+9aEPN8t4j+eWWrYY+5ixx+Ozjr0FSbm9CAO7PsnKbO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1686076228; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=E3wsEOm0W4tH0/8fNIF9dAj0SXCaI/2HSNkzbMWF33M=; b=AFPJ/xgKUgxslrmCA5n/qWdWfd5cP/C2yT9zngJW2yG2xVgqt/5xRL2mtxkQozWqKOxRaa6PfD/Llozh+h7i7GZd916WfFzzeWGCw9ihYU43kZTlVjNAC6gfIEBuDG7b3GbDEYGWz0dh32G/GjF+/ILVxih+BRy4BV3Oz2LsmKs= 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=1686076228; 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=E3wsEOm0W4tH0/8fNIF9dAj0SXCaI/2HSNkzbMWF33M=; b=kT04OZUyINNnU2sA56CYvwdAwq4qGoQVx4d7KY0Hh14wASxUdaJtbYNy8M9KGHTU bkqtwgHRDGjwpl+CpLnGJq4QQ3vRz14Njf4qA8OqmksgsXil+vbEJ/Debureek6ztYS 2q9kjulAq6L8abdhSIR8ZRPTDhS1QXgw70veLnb8= Received: from kampyooter.. (122.176.141.156 [122.176.141.156]) by mx.zoho.in with SMTPS id 1686076227912514.4061259697124; Wed, 7 Jun 2023 00:00:27 +0530 (IST) From: Siddh Raman Pant To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jani Nikula , Laurent Pinchart Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Suraj Upadhyay Message-ID: Subject: [PATCH v10 2/9] drm/print: Fix and add support for NULL as first argument in drm_* macros Date: Wed, 7 Jun 2023 00:00:03 +0530 X-Mailer: git-send-email 2.39.2 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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. Also, add support for NULL in __drm_printk, so that all the drm_* macros will hence support NULL as the first argument. This also means that deprecation comments mentioning pr_()* can now be changed to the drm equivalents. Reviewed-by: Laurent Pinchart Signed-off-by: Siddh Raman Pant --- include/drm/drm_print.h | 79 +++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index a93a387f8a1a..4b8532cf2ae6 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,9 +452,32 @@ void __drm_dev_dbg(struct _ddebug *desc, const struct = device *dev, * Prefer drm_device based logging over device or prink based logging. */ =20 +/* Helpers for struct drm_device based logging. */ + +/** + * __drm_dev_ptr - Helper function to get drm->dev pointer. + * @drm: struct drm_device pointer. + * + * RETURNS: + * The struct device pointer (NULL if @drm is NULL). + */ +static inline struct device *__drm_dev_ptr(const struct drm_device *drm) +{ +=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__) +({=09=09=09=09=09=09=09=09=09\ +=09struct device *__dev_ =3D __drm_dev_ptr(drm);=09=09=09\ +=09if (__dev_)=09=09=09=09=09=09=09\ +=09=09dev_##level##type(__dev_, "[drm] " fmt, ##__VA_ARGS__);=09\ +=09else=09=09=09=09=09=09=09=09\ +=09=09pr_##level##type("[drm] " fmt, ##__VA_ARGS__);=09=09\ +}) =20 =20 #define drm_info(drm, fmt, ...)=09=09=09=09=09\ @@ -487,25 +511,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_dev_ptr(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__) +#define drm_dbg_driver(drm, fmt, ...)=09=09=09=09=09\ +=09drm_dev_dbg(__drm_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_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_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_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_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_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_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_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_dev_ptr(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__) =20 #define drm_dbg(drm, fmt, ...)=09drm_dbg_driver(drm, fmt, ##__VA_ARGS__) =20 @@ -533,31 +557,31 @@ void __drm_err(const char *format, ...); #define _DRM_PRINTK(once, level, fmt, ...)=09=09=09=09\ =09printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__) =20 -/* NOTE: this is deprecated in favor of pr_info(). */ +/* NOTE: this is deprecated in favor of drm_info(NULL, ...). */ #define DRM_INFO(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_notice(). */ +/* NOTE: this is deprecated in favor of drm_notice(NULL, ...). */ #define DRM_NOTE(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_warn(). */ +/* NOTE: this is deprecated in favor of drm_warn(NULL, ...). */ #define DRM_WARN(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) =20 -/* NOTE: this is deprecated in favor of pr_info_once(). */ +/* NOTE: this is deprecated in favor of drm_info_once(NULL, ...). */ #define DRM_INFO_ONCE(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_notice_once(). */ +/* NOTE: this is deprecated in favor of drm_notice_once(NULL, ...). */ #define DRM_NOTE_ONCE(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_warn_once(). */ +/* NOTE: this is deprecated in favor of drm_warn_once(NULL, ...). */ #define DRM_WARN_ONCE(fmt, ...)=09=09=09=09=09=09\ =09_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) =20 -/* NOTE: this is deprecated in favor of pr_err(). */ +/* NOTE: this is deprecated in favor of drm_err(NULL, ...). */ #define DRM_ERROR(fmt, ...)=09=09=09=09=09=09\ =09__drm_err(fmt, ##__VA_ARGS__) =20 -/* NOTE: this is deprecated in favor of pr_err_ratelimited(). */ +/* NOTE: this is deprecated in favor of drm_err_ratelimited(NULL, ...). */ #define DRM_ERROR_RATELIMITED(fmt, ...)=09=09=09=09=09\ =09DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) =20 @@ -593,13 +617,14 @@ void __drm_err(const char *format, ...); #define DRM_DEBUG_DP(fmt, ...)=09=09=09=09=09=09\ =09__drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__) =20 -#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\ +#define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...)=09=09\ +({=09=09=09=09=09=09=09=09=09\ +=09static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL,=09\ +=09=09=09=09 DEFAULT_RATELIMIT_BURST);=09=09\ +=09=09=09=09=09=09=09=09=09\ +=09if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))\ +=09=09drm_dev_printk(__drm_dev_ptr(drm), KERN_DEBUG,=09=09\ +=09=09=09 fmt, ## __VA_ARGS__);=09=09=09\ }) =20 #define drm_dbg_kms_ratelimited(drm, fmt, ...) \ --=20 2.39.2