From patchwork Tue Jun 6 10:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddh Raman Pant X-Patchwork-Id: 103719 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3301107vqr; Tue, 6 Jun 2023 03:55:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5EiLgvPPVCkRE9gEecwLe2FJ15ob7TfWv1VQBL9MsahD/Sp6NFf9aFGU2RwYRAbsPYaJk5 X-Received: by 2002:a05:620a:6183:b0:75b:23a1:3ff with SMTP id or3-20020a05620a618300b0075b23a103ffmr1468032qkn.21.1686048931061; Tue, 06 Jun 2023 03:55:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686048931; cv=pass; d=google.com; s=arc-20160816; b=tlafDXY88P4AEjyNE1oJZhiPabV5fWrMlrvZjcWpFUT/QpHqLnywzItDy2MBZBzEZ+ 1Pr1UL326FTVulDk3q+kBxu+/WMpT84mnbpQ4okGtmreUpJxpkVrc3kxo9h+7AC7xzVa /oJWazIdi5y0zLJOIwfJDTr03E3r+S3u/sY9nel8wm7pfyrnlt1Lis04fGGEQnbCcKQu SfczInkKrdBjNR7D6vL3B2SiAEFSojc/5YBKGavE81tfmWZIHlDsUeu49K3eVZ3id/Q3 Ddu7FAHJqC8t8mIO3BrFPNBSbyyJ4pJTEtvTb/uPhJwi8olbttX7qpZ1JVY/QGjUGDU4 q9Dw== 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=i4Fa1up9cwOcO1Yt+8hd91eqrmOFnaJLCoQTeXNK3jo=; b=eFvS2moHw1fxOkKVWLUCD0z5wyyNN6slRFtu1vE37Ty7DzKEuwGZlgAoTbyvudyj/p lXJsqUWlzFZmi9owH80ZPy3JJu/YbjZ3SlZRpOF50xg8vruHbHwFA4EoQ/hgtozKi5bb SpHepSeyqHoI+gSxUtCD4FdxY3NiqfBkh/Ur/oZG+drGvfyiF2kVKbm+3sVOsry+6bFn xdLxmsXjTwUtB70KUm0ROIFsjbdCOtwWdDptKMas5bj8fD/jT/4iMt1cMQxSa7YHi4Zx 3zgeacRTAyujsh7BQXe2wIWsSAXuC2tkCf90VNO/vAZh7DeMbfvq0UY9ZcHUY5SryKap 7jmQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b="UD8L+D/k"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a05620a030800b007578a115e2csi5678940qkm.126.2023.06.06.03.55.16; Tue, 06 Jun 2023 03:55:31 -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="UD8L+D/k"; 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 S237386AbjFFKs3 (ORCPT + 99 others); Tue, 6 Jun 2023 06:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233206AbjFFKre (ORCPT ); Tue, 6 Jun 2023 06:47:34 -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 5935BE6B for ; Tue, 6 Jun 2023 03:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686048331; cv=none; d=zohomail.in; s=zohoarc; b=SvO/l6jxRPFLDsZcCDqFIGgYFklKV1oX9Rw9fKXpMtIb5BsYIAVFpL4e0WjQu1qqVEq5q+aDHxrvwUbsOPkNIGB6m4HeerIqPjUl31CxMmWWnWgEKWHp4D62/2MWizPi9Gwf062F1YkllAq4lVdENaMaw5+ryuSmSeEhypFY4Bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1686048331; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=i4Fa1up9cwOcO1Yt+8hd91eqrmOFnaJLCoQTeXNK3jo=; b=auAmY1q4tB7sAHtPZ7DgJTENYSi9NKZdO2F0xPl7ASfLXlf6RPJvcAPD83jbWW1LMnadCblpklNXu4czcPkmo9nEUxTG8nnZOghJVHTUP6lVl4TICKZVkGiocofluQkEiWDPNfkTEwyK3Ht+YPYbb8SNdWqFz47IqFYemzzvn7s= 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=1686048331; 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=i4Fa1up9cwOcO1Yt+8hd91eqrmOFnaJLCoQTeXNK3jo=; b=UD8L+D/kPnLiRikm8SEY3oDt+Hz04kvJNbAaBn5kDZ4YirOtxd9rORUMT75wfwtu lcr2mysysNVSuKFY8q9Errdp0list64vIadRepEiEORo//WIz8XSa0RJCJy6zDy14su OOXjqAtwA19djxFTiW9DQEhb3/W3Yz2a2v9R6/38= Received: from kampyooter.. (122.176.141.156 [122.176.141.156]) by mx.zoho.in with SMTPS id 1686048328984432.71534248743194; Tue, 6 Jun 2023 16:15:28 +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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Suraj Upadhyay Message-ID: Subject: [PATCH v9 2/8] drm/print: Fix and add support for NULL as first argument in drm_* macros Date: Tue, 6 Jun 2023 16:15:16 +0530 X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-ZohoMailClient: External 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767950443870270940?= X-GMAIL-MSGID: =?utf-8?q?1767950443870270940?= 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. Signed-off-by: Siddh Raman Pant Reviewed-by: Laurent Pinchart --- 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 #include +#include /* 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. */ +/* 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) +{ + if (drm) + return drm->dev; + + return NULL; +} + /* Helper for struct drm_device based logging. */ #define __drm_printk(drm, level, type, fmt, ...) \ - dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__) +({ \ + struct device *__dev_ = __drm_dev_ptr(drm); \ + if (__dev_) \ + dev_##level##type(__dev_, "[drm] " fmt, ##__VA_ARGS__); \ + else \ + pr_##level##type("[drm] " fmt, ##__VA_ARGS__); \ +}) #define drm_info(drm, fmt, ...) \ @@ -487,25 +511,25 @@ void __drm_dev_dbg(struct _ddebug *desc, const struct device *dev, #define drm_dbg_core(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__) -#define drm_dbg_driver(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__) +#define drm_dbg_driver(drm, fmt, ...) \ + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_DRIVER, fmt, ##__VA_ARGS__) #define drm_dbg_kms(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_KMS, fmt, ##__VA_ARGS__) #define drm_dbg_prime(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_PRIME, fmt, ##__VA_ARGS__) #define drm_dbg_atomic(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) #define drm_dbg_vbl(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_VBL, fmt, ##__VA_ARGS__) #define drm_dbg_state(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_STATE, fmt, ##__VA_ARGS__) #define drm_dbg_lease(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_LEASE, fmt, ##__VA_ARGS__) #define drm_dbg_dp(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_DP, fmt, ##__VA_ARGS__) #define drm_dbg_drmres(drm, fmt, ...) \ - drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS__) + drm_dev_dbg(__drm_dev_ptr(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__) #define drm_dbg(drm, fmt, ...) drm_dbg_driver(drm, fmt, ##__VA_ARGS__) @@ -533,31 +557,31 @@ void __drm_err(const char *format, ...); #define _DRM_PRINTK(once, level, fmt, ...) \ printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_info(). */ +/* NOTE: this is deprecated in favor of drm_info(NULL, ...). */ #define DRM_INFO(fmt, ...) \ _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, ...) \ _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, ...) \ _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) -/* 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, ...) \ _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, ...) \ _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, ...) \ _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) -/* NOTE: this is deprecated in favor of pr_err(). */ +/* NOTE: this is deprecated in favor of drm_err(NULL, ...). */ #define DRM_ERROR(fmt, ...) \ __drm_err(fmt, ##__VA_ARGS__) -/* 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, ...) \ DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) @@ -593,13 +617,14 @@ void __drm_err(const char *format, ...); #define DRM_DEBUG_DP(fmt, ...) \ __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__) -#define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...) \ -({ \ - static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\ - const struct drm_device *drm_ = (drm); \ - \ - if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_)) \ - drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARGS__); \ +#define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...) \ +({ \ + static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))\ + drm_dev_printk(__drm_dev_ptr(drm), KERN_DEBUG, \ + fmt, ## __VA_ARGS__); \ }) #define drm_dbg_kms_ratelimited(drm, fmt, ...) \