Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6183347rwl; Mon, 9 Jan 2023 05:23:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQlujygMY6W3XJ5z1YBcXlfdJCsjYHuZcptOA8SZy3TvuGLcP2eYtcue454b/OObK0T60l X-Received: by 2002:a05:6402:1ca4:b0:497:b6bc:b811 with SMTP id cz4-20020a0564021ca400b00497b6bcb811mr8166013edb.33.1673270589916; Mon, 09 Jan 2023 05:23:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673270589; cv=pass; d=google.com; s=arc-20160816; b=0NyvnOHdGD6YXd1WcKRcBmy15/au0S/j2152mVrw+Ukjzwo1iH1if9NKveEbsf8SF8 M9nigCXbb5T2+Lr0bLsbo6RjZr/CCBMJPzewsQHF8/HnZbYtxSjQt9CRBPrq3C0/LIhe Ac4UU2iyru+NpaN/4HvkL3ZdLZO21Ygi8qI5tLMhK2GLkdaCQBB3Wt4heeTdPR2NaKE1 J8LWNQJt/6z/E6GlB71FSFDOVlvIhaNW31Gh45UWxwSxZeQ6llNUg+lS3OIM6ee3dybS n3UlNZtBQM6AlUwSfqwB5BLQljfmPR0m8usyTaWe8NeG/zpqvNltJDrhQCt4G6V3qZ73 rgQw== 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=buHlbps7oBJIveBp1ddf9gVwRH69D6PkDKAYKL401aA=; b=TO5ayUOMi1d/+fik9P1zUS9Up/5dVH8QzUFhKgu8H81TEMrmEKvfWp78AUnnaxTxrk 1YyUm6psaFU3Zs1HYLzf5RTQSs8Lu10tetKl+M7+FJ+rjfTXek1feFbXPlHBjgu5PypF 1TEV+J3GTkrU8dn8iboW2fNlZZCicl+0NNLUqVfH95/gw7l7MbuxUkoDJ6Y3kn3gr4y4 gIol7lXLETpH2R2AHdd8kvvQdGWvCWXm0YrNBSI6aswxLUpf4m0Z9b0QWKWHF/c5IJW9 qy+jKqZAAUyhO6Gt9eN4XrtKAESdc8g/YT0ED/adwr4GCQc9O2yD5lEsqeIhFsVnRSXh lPIw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=gjlcQjMd; 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 z10-20020a05640235ca00b0046289aad428si10518980edc.496.2023.01.09.05.22.56; Mon, 09 Jan 2023 05:23:09 -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=gjlcQjMd; 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 S237152AbjAINDe (ORCPT + 52 others); Mon, 9 Jan 2023 08:03:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236492AbjAINCp (ORCPT ); Mon, 9 Jan 2023 08:02:45 -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 F34A3D6B for ; Mon, 9 Jan 2023 05:01:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673269260; cv=none; d=zohomail.in; s=zohoarc; b=CAnVqG+R2gG8OGrvsEBD2wjKbcFZzxuV6KmgnB1lydzCFl0zt0lTWxrWre4iu5hVgyNxbhWOsqApFt68TtDm18M3X0/WDM0+7sueue98fv+dnutWWuyqVWf+2znSEaXRu0xVfY/QDktn8A68uC4HOvYsY2PYogDfGnXRbvvyHVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1673269260; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=buHlbps7oBJIveBp1ddf9gVwRH69D6PkDKAYKL401aA=; b=dJvMXrO2PM7dDd+ryQ5acMiAPR36TwXV068pA7oEVAp515V8Oepsu1OF0Rn64V3qFJc4LphvhyKcbEn8tfsPnLHgbF/zhCdzQpSwv5SsKF1kMtCh6obem1bIkbE70Dtda8gjQj/TdK7ykdkaiBEk6fIUFzyC5CaKGLlNOcdh3sU= 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=1673269260; 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=buHlbps7oBJIveBp1ddf9gVwRH69D6PkDKAYKL401aA=; b=gjlcQjMdg4mbObwFoJWTcL3y0VYbzRuCrHYKLsV+wqFYwZeION6AAdFoM4oUthZ8 8sDIMqc7RDn5lyIGdy0yp8660hkqitMCi3FhcF1Eo6k4krC8OonDQGD4R69E8eGV4ep sFTXoeZpD2KAvn0I2Dhj4/bhISvXQaCrgbifMIVI= Received: from kampyooter.. (110.226.31.37 [110.226.31.37]) by mx.zoho.in with SMTPS id 1673269249386699.3287856168425; Mon, 9 Jan 2023 18:30:49 +0530 (IST) From: Siddh Raman Pant To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Simon Ser , Jim Cromie , Sam Ravnborg Cc: dri-devel , linux-kernel Message-ID: <9aee0b579d5b82b07083a9b611927a7a61e21a1d.1673269059.git.code@siddh.me> Subject: [PATCH v6 01/10] drm/print: Fix and add support for NULL as first argument in drm_* macros Date: Mon, 9 Jan 2023 18:30:26 +0530 X-Mailer: git-send-email 2.39.0 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. 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. There is a need to support device pointers, as in some cases, we may not have drm_device but just the device ptr, such as when dealing with struct mipi_dsi_host. Before this change, passing just mipi_dsi_host would have worked, since due to preprocessing, the resultant would be "host->dev", but now due to NULL check that cannot happen. Signed-off-by: Siddh Raman Pant --- include/drm/drm_print.h | 114 ++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 27 deletions(-) diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index a44fb7ef257f..481bf129cc39 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; @@ -445,15 +446,73 @@ void __drm_dev_dbg(struct _ddebug *desc, const struct= device *dev, #define DRM_DEV_DEBUG_KMS(dev, fmt, ...)=09=09=09=09\ =09drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__) =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; +} + +/** + * __dev_ptr - Helper function to get the same device pointer. + * @dev: struct device pointer, or NULL. + * + * RETURNS: + * The struct device pointer (NULL if @dev is NULL). + */ +static inline struct device *__dev_ptr(const struct device *dev) +{ +=09return (struct device *)dev; +} + +/** + * __get_dev_ptr - Helper to get device pointer given struct drm_device *, + *=09=09 or struct device *, or NULL. + * + * Primarily for use in drm_*() print macros, since they need to handle NU= LL + * as the first argument passed. + * + * struct device pointers are supported for edge cases (such as mipi_dsi_h= ost), + * the default (and recommended) way is to pass struct drm_device pointer. + */ +#define __get_dev_ptr(drm)=09=09=09\ +=09_Generic((drm),=09=09=09=09\ +=09=09struct device * :=09=09\ +=09=09=09__dev_ptr,=09=09\ +=09=09const struct device * :=09=09\ +=09=09=09__dev_ptr,=09=09\ +=09=09default :=09=09=09\ +=09=09=09__drm_dev_ptr=09=09\ +=09)(drm) + /* * struct drm_device based logging * * Prefer drm_device based logging over device or prink based logging. + * + * The below macros support device pointers to cope for edge cases where + * we only have device (like in mipi_dsi_host) but not drm_device. */ =20 /* 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 __get_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 +546,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(__get_dev_ptr(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__) +#define drm_dbg_driver(drm, fmt, ...)=09=09=09=09=09\ +=09drm_dev_dbg(__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(__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(__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(__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(__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(__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(__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(__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(__get_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 +592,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 +652,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(__get_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.0