Add a wrapper to kref_read() just like the ones already in place for
kref_get() and kref_put(). This will be used for sanity checks on object
lifetime.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/drm_mode_object.c | 20 ++++++++++++++++++++
include/drm/drm_mode_object.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c
index df4cc0e8e263d5887a799cf1a61d998234be7158..f990cc7e9b5d3bda3453123593314fa1ea2bf923 100644
--- a/drivers/gpu/drm/drm_mode_object.c
+++ b/drivers/gpu/drm/drm_mode_object.c
@@ -217,6 +217,26 @@ void drm_mode_object_get(struct drm_mode_object *obj)
}
EXPORT_SYMBOL(drm_mode_object_get);
+/**
+ * drm_mode_object_get - read the refcount for a mode object
+ * @obj: DRM mode object
+ *
+ * This function returns the current object's refcount if it is a
+ * refcounted modeset object, or 0 on any other object.
+ */
+unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj)
+{
+ unsigned int refcount = 0;
+
+ if (obj->free_cb) {
+ refcount = kref_read(&obj->refcount);
+ DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, refcount);
+ }
+
+ return refcount;
+}
+EXPORT_SYMBOL(drm_mode_object_read_refcount);
+
/**
* drm_object_attach_property - attach a property to a modeset object
* @obj: drm modeset object
diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h
index c68edbd126d04d51221f50aa2b4166475543b59f..3d2c739e703888bf4520c61594d480f128d50e56 100644
--- a/include/drm/drm_mode_object.h
+++ b/include/drm/drm_mode_object.h
@@ -123,6 +123,7 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
uint32_t id, uint32_t type);
void drm_mode_object_get(struct drm_mode_object *obj);
void drm_mode_object_put(struct drm_mode_object *obj);
+unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj);
int drm_object_property_set_value(struct drm_mode_object *obj,
struct drm_property *property,
--
2.34.1
Hi Luca, kernel test robot noticed the following build warnings: [auto build test WARNING on 42f7652d3eb527d03665b09edac47f85fb600924] url: https://github.com/intel-lab-lkp/linux/commits/Luca-Ceresoli/drm-drm_mode_object-fix-typo-in-kerneldoc/20241106-185032 base: 42f7652d3eb527d03665b09edac47f85fb600924 patch link: https://lore.kernel.org/r/20241106-drm-small-improvements-v2-3-f6e2aef86719%40bootlin.com patch subject: [PATCH v2 3/4] drm/mode_object: add drm_mode_object_read_refcount() config: arc-randconfig-002-20241106 (https://download.01.org/0day-ci/archive/20241107/202411070038.tZJzI7NC-lkp@intel.com/config) compiler: arc-elf-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241107/202411070038.tZJzI7NC-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202411070038.tZJzI7NC-lkp@intel.com/ All warnings (new ones prefixed by >>): >> drivers/gpu/drm/drm_mode_object.c:228: warning: expecting prototype for drm_mode_object_get(). Prototype was for drm_mode_object_read_refcount() instead vim +228 drivers/gpu/drm/drm_mode_object.c 219 220 /** 221 * drm_mode_object_get - read the refcount for a mode object 222 * @obj: DRM mode object 223 * 224 * This function returns the current object's refcount if it is a 225 * refcounted modeset object, or 0 on any other object. 226 */ 227 unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj) > 228 { 229 unsigned int refcount = 0; 230 231 if (obj->free_cb) { 232 refcount = kref_read(&obj->refcount); 233 DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, refcount); 234 } 235 236 return refcount; 237 } 238 EXPORT_SYMBOL(drm_mode_object_read_refcount); 239 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On Wed, 06 Nov 2024, Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: > Add a wrapper to kref_read() just like the ones already in place for > kref_get() and kref_put(). This will be used for sanity checks on object > lifetime. > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > --- > drivers/gpu/drm/drm_mode_object.c | 20 ++++++++++++++++++++ > include/drm/drm_mode_object.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c > index df4cc0e8e263d5887a799cf1a61d998234be7158..f990cc7e9b5d3bda3453123593314fa1ea2bf923 100644 > --- a/drivers/gpu/drm/drm_mode_object.c > +++ b/drivers/gpu/drm/drm_mode_object.c > @@ -217,6 +217,26 @@ void drm_mode_object_get(struct drm_mode_object *obj) > } > EXPORT_SYMBOL(drm_mode_object_get); > > +/** > + * drm_mode_object_get - read the refcount for a mode object > + * @obj: DRM mode object > + * > + * This function returns the current object's refcount if it is a > + * refcounted modeset object, or 0 on any other object. Returns: The current object's ... > + */ > +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj) > +{ > + unsigned int refcount = 0; > + > + if (obj->free_cb) { > + refcount = kref_read(&obj->refcount); > + DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, refcount); Please ditch the debug. > + } > + > + return refcount; > +} > +EXPORT_SYMBOL(drm_mode_object_read_refcount); > + > /** > * drm_object_attach_property - attach a property to a modeset object > * @obj: drm modeset object > diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h > index c68edbd126d04d51221f50aa2b4166475543b59f..3d2c739e703888bf4520c61594d480f128d50e56 100644 > --- a/include/drm/drm_mode_object.h > +++ b/include/drm/drm_mode_object.h > @@ -123,6 +123,7 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, > uint32_t id, uint32_t type); > void drm_mode_object_get(struct drm_mode_object *obj); > void drm_mode_object_put(struct drm_mode_object *obj); > +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj); > > int drm_object_property_set_value(struct drm_mode_object *obj, > struct drm_property *property, -- Jani Nikula, Intel
Hello Jani, On Wed, 06 Nov 2024 14:03:08 +0200 Jani Nikula <jani.nikula@linux.intel.com> wrote: > On Wed, 06 Nov 2024, Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: > > Add a wrapper to kref_read() just like the ones already in place for > > kref_get() and kref_put(). This will be used for sanity checks on object > > lifetime. > > > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > --- > > drivers/gpu/drm/drm_mode_object.c | 20 ++++++++++++++++++++ > > include/drm/drm_mode_object.h | 1 + > > 2 files changed, 21 insertions(+) > > > > diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c > > index df4cc0e8e263d5887a799cf1a61d998234be7158..f990cc7e9b5d3bda3453123593314fa1ea2bf923 100644 > > --- a/drivers/gpu/drm/drm_mode_object.c > > +++ b/drivers/gpu/drm/drm_mode_object.c > > @@ -217,6 +217,26 @@ void drm_mode_object_get(struct drm_mode_object *obj) > > } > > EXPORT_SYMBOL(drm_mode_object_get); > > > > +/** > > + * drm_mode_object_get - read the refcount for a mode object > > + * @obj: DRM mode object > > + * > > + * This function returns the current object's refcount if it is a > > + * refcounted modeset object, or 0 on any other object. > > Returns: The current object's ... > > > + */ > > +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj) > > +{ > > + unsigned int refcount = 0; > > + > > + if (obj->free_cb) { > > + refcount = kref_read(&obj->refcount); > > + DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, refcount); > > Please ditch the debug. OK, will do both in v3. Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
© 2016 - 2024 Red Hat, Inc.