2022-12-22 15:53:25

by Siddh Raman Pant

[permalink] [raw]
Subject: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument of drm_dbg_*

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 <[email protected]>
---
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 <linux/dynamic_debug.h>

#include <drm/drm.h>
+#include <drm/drm_device.h>

/* 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.
*/

+/**
+ * __drm_get_dev_ptr - Helper function to get device type pointer even if NULL
+ * is passed. Primarily for use in print macros, since they
+ * 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 *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__)
@@ -487,25 +504,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_get_dev_ptr(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__)
+#define drm_dbg_driver(drm, fmt, ...) \
+ drm_dev_dbg(__drm_get_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_get_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_get_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_get_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_get_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_get_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_get_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_get_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_get_dev_ptr(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__)

#define drm_dbg(drm, fmt, ...) drm_dbg_driver(drm, fmt, ##__VA_ARGS__)

@@ -596,10 +613,9 @@ void __drm_err(const char *format, ...);
#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__); \
+ drm_dev_printk(__drm_get_dev_ptr(drm), KERN_DEBUG, fmt, ## __VA_ARGS__); \
})

#define drm_dbg_kms_ratelimited(drm, fmt, ...) \
--
2.35.1



2022-12-24 23:58:17

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument of drm_dbg_*

Hi Siddh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20221220]
[also build test WARNING on linus/master]
[cannot apply to drm-misc/drm-misc-next v6.1 v6.1-rc8 v6.1-rc7 v6.1]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Siddh-Raman-Pant/drm-Remove-usage-of-deprecated-DRM_INFO/20221222-235336
patch link: https://lore.kernel.org/r/cd397a877b94ec8062440e3ae6a6a4f1af82d854.1671723195.git.code%40siddh.me
patch subject: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument of drm_dbg_*
reproduce:
# https://github.com/intel-lab-lkp/linux/commit/5b7a52481bf09de1326e265c6a8024de14cfc01a
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Siddh-Raman-Pant/drm-Remove-usage-of-deprecated-DRM_INFO/20221222-235336
git checkout 5b7a52481bf09de1326e265c6a8024de14cfc01a
make menuconfig
# enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS
make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> Documentation/gpu/drm-internals:194: ./include/drm/drm_print.h:459: WARNING: Inline emphasis start-string without end-string.

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (1.59 kB)
config (40.04 kB)
Download all attachments