Re: [PATCH 3/4] drm/plane: add drmm_universal_plane_alloc()
Hi Philipp, url: https://github.com/0day-ci/linux/commits/Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: x86_64-randconfig-m001-20200826 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot Reported-by: Dan Carpenter New smatch warnings: drivers/gpu/drm/drm_plane.c:302 drm_universal_plane_init() error: uninitialized symbol 'ap'. drivers/gpu/drm/drm_plane.c:345 __drmm_universal_plane_alloc() error: uninitialized symbol 'ap'. Old smatch warnings: drivers/gpu/drm/drm_plane.c:117 create_in_format_blob() error: potential null dereference 'blob'. (drm_property_create_blob returns null) # https://github.com/0day-ci/linux/commit/d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 git checkout d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 vim +/ap +302 drivers/gpu/drm/drm_plane.c d809a51da3d293 Philipp Zabel 2020-08-26 287 int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, d809a51da3d293 Philipp Zabel 2020-08-26 288 uint32_t possible_crtcs, d809a51da3d293 Philipp Zabel 2020-08-26 289 const struct drm_plane_funcs *funcs, d809a51da3d293 Philipp Zabel 2020-08-26 290 const uint32_t *formats, unsigned int format_count, d809a51da3d293 Philipp Zabel 2020-08-26 291 const uint64_t *format_modifiers, d809a51da3d293 Philipp Zabel 2020-08-26 292 enum drm_plane_type type, d809a51da3d293 Philipp Zabel 2020-08-26 293 const char *name, ...) d809a51da3d293 Philipp Zabel 2020-08-26 294 { d809a51da3d293 Philipp Zabel 2020-08-26 295va_list ap; ^^ d809a51da3d293 Philipp Zabel 2020-08-26 296int ret; d809a51da3d293 Philipp Zabel 2020-08-26 297 d809a51da3d293 Philipp Zabel 2020-08-26 298if (name) d809a51da3d293 Philipp Zabel 2020-08-26 299va_start(ap, name); ^^ d809a51da3d293 Philipp Zabel 2020-08-26 300ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs, d809a51da3d293 Philipp Zabel 2020-08-26 301 formats, format_count, format_modifiers, d809a51da3d293 Philipp Zabel 2020-08-26 @302 type, name, ap); ^^ This isn't always initialized. Presumably it's not a problem but runtime tools like KASan (syzbot) will detect the load and complain as well so it's probably better to silence it. d809a51da3d293 Philipp Zabel 2020-08-26 303if (name) d809a51da3d293 Philipp Zabel 2020-08-26 304va_end(ap); d809a51da3d293 Philipp Zabel 2020-08-26 305return ret; d809a51da3d293 Philipp Zabel 2020-08-26 306 } 43968d7b806d7a Daniel Vetter 2016-09-21 307 EXPORT_SYMBOL(drm_universal_plane_init); 43968d7b806d7a Daniel Vetter 2016-09-21 308 d809a51da3d293 Philipp Zabel 2020-08-26 309 static void drmm_universal_plane_alloc_release(struct drm_device *dev, void *ptr) d809a51da3d293 Philipp Zabel 2020-08-26 310 { d809a51da3d293 Philipp Zabel 2020-08-26 311struct drm_plane *plane = ptr; d809a51da3d293 Philipp Zabel 2020-08-26 312 d809a51da3d293 Philipp Zabel 2020-08-26 313if (WARN_ON(!plane->dev)) d809a51da3d293 Philipp Zabel 2020-08-26 314return; d809a51da3d293 Philipp Zabel 2020-08-26 315 d809a51da3d293 Philipp Zabel 2020-08-26 316drm_plane_cleanup(plane); d809a51da3d293 Philipp Zabel 2020-08-26 317 } d809a51da3d293 Philipp Zabel 2020-08-26 318 d809a51da3d293 Philipp Zabel 2020-08-26 319 void *__drmm_universal_plane_alloc(struct drm_device *dev, size_t size, d809a51da3d293 Philipp Zabel 2020-08-26 320 size_t offset, uint32_t possible_crtcs, d809a51da3d293 Philipp Zabel 2020-08-26 321 const struct drm_plane_funcs *funcs, d809a51da3d293 Philipp Zabel 2020-08-26 322 const uint32_t *formats, unsigned int format_count, d809a51da3d293 Philipp Zabel 2020-08-26 323 const uint64_t *format_modifiers, d809a51da3d293 Philipp Zabel 2020-08-26 324 enum drm_plane_type type, d809a51da3d293 Philipp Zabel 2020-08-26 325 const char *name, ...) d809a51da3d293 Philipp Zabel 2020-08-26 326 { d809a51da3d293 Philipp Zabel 2020-08-26 327void *container; d809a51da3d293 Philipp Zabel 2020-08-26 328struct drm_plane *plane; d809a51da3d293 Philipp Zabel 2020-08-26 329
Re: [PATCH 3/4] drm/plane: add drmm_universal_plane_alloc()
Hi Philipp, I love your patch! Perhaps something to improve: [auto build test WARNING on drm-intel/for-linux-next] [also build test WARNING on tegra-drm/drm/tegra/for-next drm-tip/drm-tip linus/master drm-exynos/exynos-drm-next v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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] url: https://github.com/0day-ci/linux/commits/Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: x86_64-randconfig-a003-20200826 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 7cfcecece0e0430937cf529ce74d3a071a4dedc6) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install x86_64 cross compiling tool for clang build # apt-get install binutils-x86-64-linux-gnu # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All warnings (new ones prefixed by >>): >> drivers/gpu/drm/drm_plane.c:156:5: warning: no previous prototype for >> function '__drm_universal_plane_init' [-Wmissing-prototypes] int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, ^ drivers/gpu/drm/drm_plane.c:156:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, ^ static 1 warning generated. # https://github.com/0day-ci/linux/commit/d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 git checkout d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 vim +/__drm_universal_plane_init +156 drivers/gpu/drm/drm_plane.c 155 > 156 int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane > *plane, 157 uint32_t possible_crtcs, 158 const struct drm_plane_funcs *funcs, 159 const uint32_t *formats, unsigned int format_count, 160 const uint64_t *format_modifiers, 161 enum drm_plane_type type, 162 const char *name, va_list ap) 163 { 164 struct drm_mode_config *config = >mode_config; 165 unsigned int format_modifier_count = 0; 166 int ret; 167 168 /* plane index is used with 32bit bitmasks */ 169 if (WARN_ON(config->num_total_plane >= 32)) 170 return -EINVAL; 171 172 WARN_ON(drm_drv_uses_atomic_modeset(dev) && 173 (!funcs->atomic_destroy_state || 174 !funcs->atomic_duplicate_state)); 175 176 ret = drm_mode_object_add(dev, >base, DRM_MODE_OBJECT_PLANE); 177 if (ret) 178 return ret; 179 180 drm_modeset_lock_init(>mutex); 181 182 plane->base.properties = >properties; 183 plane->dev = dev; 184 plane->funcs = funcs; 185 plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), 186 GFP_KERNEL); 187 if (!plane->format_types) { 188 DRM_DEBUG_KMS("out of memory when allocating plane\n"); 189 drm_mode_object_unregister(dev, >base); 190 return -ENOMEM; 191 } 192 193 /* 194 * First driver to need more than 64 formats needs to fix this. Each 195 * format is encoded as a bit and the current code only supports a u64. 196 */ 197 if (WARN_ON(format_count > 64)) 198 return -EINVAL; 199 200 if (format_modifiers) { 201 const uint64_t *temp_modifiers = format_modifiers; 202 203 while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID) 204 format_modifier_count++; 205 } 206 207 if (format_modifier_count) 208 config->allow_fb_modifiers = true; 209 210 plane->modifier_count = format_modifier_count; 211 plane->modifiers = kmalloc_array(format_modifier_count, 212 sizeof(format_modifiers[0]), 213
Re: [PATCH 3/4] drm/plane: add drmm_universal_plane_alloc()
Hi Philipp, I love your patch! Perhaps something to improve: [auto build test WARNING on drm-intel/for-linux-next] [also build test WARNING on tegra-drm/drm/tegra/for-next drm-tip/drm-tip linus/master drm-exynos/exynos-drm-next v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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] url: https://github.com/0day-ci/linux/commits/Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: arm-randconfig-r001-20200826 (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All warnings (new ones prefixed by >>): >> drivers/gpu/drm/drm_plane.c:156:5: warning: no previous prototype for >> '__drm_universal_plane_init' [-Wmissing-prototypes] 156 | int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, | ^~ drivers/gpu/drm/drm_plane.c: In function '__drm_universal_plane_init': >> drivers/gpu/drm/drm_plane.c:223:3: warning: function >> '__drm_universal_plane_init' might be a candidate for 'gnu_printf' format >> attribute [-Wsuggest-attribute=format] 223 | plane->name = kvasprintf(GFP_KERNEL, name, ap); | ^ # https://github.com/0day-ci/linux/commit/d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 git checkout d809a51da3d2939a84ecf6b4ada8f5be6c3ecb35 vim +/__drm_universal_plane_init +156 drivers/gpu/drm/drm_plane.c 155 > 156 int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane > *plane, 157 uint32_t possible_crtcs, 158 const struct drm_plane_funcs *funcs, 159 const uint32_t *formats, unsigned int format_count, 160 const uint64_t *format_modifiers, 161 enum drm_plane_type type, 162 const char *name, va_list ap) 163 { 164 struct drm_mode_config *config = >mode_config; 165 unsigned int format_modifier_count = 0; 166 int ret; 167 168 /* plane index is used with 32bit bitmasks */ 169 if (WARN_ON(config->num_total_plane >= 32)) 170 return -EINVAL; 171 172 WARN_ON(drm_drv_uses_atomic_modeset(dev) && 173 (!funcs->atomic_destroy_state || 174 !funcs->atomic_duplicate_state)); 175 176 ret = drm_mode_object_add(dev, >base, DRM_MODE_OBJECT_PLANE); 177 if (ret) 178 return ret; 179 180 drm_modeset_lock_init(>mutex); 181 182 plane->base.properties = >properties; 183 plane->dev = dev; 184 plane->funcs = funcs; 185 plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), 186 GFP_KERNEL); 187 if (!plane->format_types) { 188 DRM_DEBUG_KMS("out of memory when allocating plane\n"); 189 drm_mode_object_unregister(dev, >base); 190 return -ENOMEM; 191 } 192 193 /* 194 * First driver to need more than 64 formats needs to fix this. Each 195 * format is encoded as a bit and the current code only supports a u64. 196 */ 197 if (WARN_ON(format_count > 64)) 198 return -EINVAL; 199 200 if (format_modifiers) { 201 const uint64_t *temp_modifiers = format_modifiers; 202 203 while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID) 204 format_modifier_count++; 205 } 206 207 if (format_modifier_count) 208 config->allow_fb_modifiers = true; 209 210 plane->modifier_count = format_modifier_count; 211 plane->modifiers = kmalloc_array(format_modifier_count, 212 sizeof(format_modifiers[0]), 213 GFP_KERNEL); 214 215 if (format_modifier_count && !plane->modifiers) {
Re: [PATCH 3/4] drm/plane: add drmm_universal_plane_alloc()
Hi Philipp, I love your patch! Perhaps something to improve: [auto build test WARNING on drm-intel/for-linux-next] [also build test WARNING on tegra-drm/drm/tegra/for-next drm-tip/drm-tip linus/master drm-exynos/exynos-drm-next v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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] url: https://github.com/0day-ci/linux/commits/Philipp-Zabel/drm-add-drmm_encoder_alloc/20200826-203629 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: i386-randconfig-s001-20200826 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-191-g10164920-dirty # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot sparse warnings: (new ones prefixed by >>) >> drivers/gpu/drm/drm_plane.c:156:5: sparse: sparse: symbol >> '__drm_universal_plane_init' was not declared. Should it be static? Please review and possibly fold the followup patch. --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org .config.gz Description: application/gzip ___ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel
[PATCH 3/4] drm/plane: add drmm_universal_plane_alloc()
Add an alternative to drm_universal_plane_init() that allocates and initializes a plane and registers drm_plane_cleanup() with drmm_add_action_or_reset(). Signed-off-by: Philipp Zabel --- drivers/gpu/drm/drm_plane.c | 127 include/drm/drm_plane.h | 42 2 files changed, 140 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index b7b90b3a2e38..0a565d97650c 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "drm_crtc_internal.h" @@ -152,31 +153,13 @@ static int create_in_format_blob(struct drm_device *dev, struct drm_plane *plane return 0; } -/** - * drm_universal_plane_init - Initialize a new universal plane object - * @dev: DRM device - * @plane: plane object to init - * @possible_crtcs: bitmask of possible CRTCs - * @funcs: callbacks for the new plane - * @formats: array of supported formats (DRM_FORMAT\_\*) - * @format_count: number of elements in @formats - * @format_modifiers: array of struct drm_format modifiers terminated by - *DRM_FORMAT_MOD_INVALID - * @type: type of plane (overlay, primary, cursor) - * @name: printf style format string for the plane name, or NULL for default name - * - * Initializes a plane object of type @type. - * - * Returns: - * Zero on success, error code on failure. - */ -int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, -uint32_t possible_crtcs, -const struct drm_plane_funcs *funcs, -const uint32_t *formats, unsigned int format_count, -const uint64_t *format_modifiers, -enum drm_plane_type type, -const char *name, ...) +int __drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, + uint32_t possible_crtcs, + const struct drm_plane_funcs *funcs, + const uint32_t *formats, unsigned int format_count, + const uint64_t *format_modifiers, + enum drm_plane_type type, + const char *name, va_list ap) { struct drm_mode_config *config = >mode_config; unsigned int format_modifier_count = 0; @@ -237,11 +220,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, } if (name) { - va_list ap; - - va_start(ap, name); plane->name = kvasprintf(GFP_KERNEL, name, ap); - va_end(ap); } else { plane->name = kasprintf(GFP_KERNEL, "plane-%d", drm_num_planes(dev)); @@ -286,8 +265,98 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, return 0; } + +/** + * drm_universal_plane_init - Initialize a new universal plane object + * @dev: DRM device + * @plane: plane object to init + * @possible_crtcs: bitmask of possible CRTCs + * @funcs: callbacks for the new plane + * @formats: array of supported formats (DRM_FORMAT\_\*) + * @format_count: number of elements in @formats + * @format_modifiers: array of struct drm_format modifiers terminated by + *DRM_FORMAT_MOD_INVALID + * @type: type of plane (overlay, primary, cursor) + * @name: printf style format string for the plane name, or NULL for default name + * + * Initializes a plane object of type @type. + * + * Returns: + * Zero on success, error code on failure. + */ +int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, +uint32_t possible_crtcs, +const struct drm_plane_funcs *funcs, +const uint32_t *formats, unsigned int format_count, +const uint64_t *format_modifiers, +enum drm_plane_type type, +const char *name, ...) +{ + va_list ap; + int ret; + + if (name) + va_start(ap, name); + ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs, +formats, format_count, format_modifiers, +type, name, ap); + if (name) + va_end(ap); + return ret; +} EXPORT_SYMBOL(drm_universal_plane_init); +static void drmm_universal_plane_alloc_release(struct drm_device *dev, void *ptr) +{ + struct drm_plane *plane = ptr; + + if (WARN_ON(!plane->dev)) + return; + + drm_plane_cleanup(plane); +} + +void *__drmm_universal_plane_alloc(struct drm_device *dev, size_t size, + size_t offset, uint32_t