On Wed, Jan 03, 2018 at 11:21:06PM +0100, Noralf Trønnes wrote: > If struct fb_ops is defined in a library like cma, fb_open() and fbcon > takes a ref on the library instead of the driver module. Use > fb_ops.fb_open/fb_release to ensure that the driver module is pinned. > > Signed-off-by: Noralf Trønnes <noralf@xxxxxxxxxxx> > --- > drivers/gpu/drm/drm_fb_helper.c | 40 ++++++++++++++++++++++++++++++++++++++++ > include/drm/drm_fb_helper.h | 13 +++++++++++++ > 2 files changed, 53 insertions(+) > > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 035784ddd133..2c6adf1d80c2 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -1207,6 +1207,46 @@ void drm_fb_helper_cfb_imageblit(struct fb_info *info, > } > EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit); > > +/** > + * drm_fb_helper_fb_open - implementation for &fb_ops.fb_open > + * @info: fbdev registered by the helper > + * @user: 1=userspace, 0=fbcon > + * > + * If &fb_ops is wrapped in a library, pin the driver module. > + */ > +int drm_fb_helper_fb_open(struct fb_info *info, int user) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_device *dev = fb_helper->dev; > + > + if (info->fbops->owner != dev->driver->fops->owner) { Actually bikeshed potential here: I'd just unconditionally grab the module reference, makes the code simpler. Or is there a reason not to? -Daniel > + if (!try_module_get(dev->driver->fops->owner)) > + return -ENODEV; > + } > + > + return 0; > +} > +EXPORT_SYMBOL(drm_fb_helper_fb_open); > + > +/** > + * drm_fb_helper_fb_release - implementation for &fb_ops.fb_release > + * @info: fbdev registered by the helper > + * @user: 1=userspace, 0=fbcon > + * > + * If &fb_ops is wrapped in a library, unpin the driver module. > + */ > +int drm_fb_helper_fb_release(struct fb_info *info, int user) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_device *dev = fb_helper->dev; > + > + if (info->fbops->owner != dev->driver->fops->owner) > + module_put(dev->driver->fops->owner); > + > + return 0; > +} > +EXPORT_SYMBOL(drm_fb_helper_fb_release); > + > /** > * drm_fb_helper_set_suspend - wrapper around fb_set_suspend > * @fb_helper: driver-allocated fbdev helper, can be NULL > diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h > index b069433e7fc1..a593f01ff69e 100644 > --- a/include/drm/drm_fb_helper.h > +++ b/include/drm/drm_fb_helper.h > @@ -297,6 +297,9 @@ void drm_fb_helper_cfb_copyarea(struct fb_info *info, > void drm_fb_helper_cfb_imageblit(struct fb_info *info, > const struct fb_image *image); > > +int drm_fb_helper_fb_open(struct fb_info *info, int user); > +int drm_fb_helper_fb_release(struct fb_info *info, int user); > + > void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend); > void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper, > bool suspend); > @@ -473,6 +476,16 @@ static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info, > { > } > > +static inline int drm_fb_helper_fb_open(struct fb_info *info, int user) > +{ > + return -ENODEV; > +} > + > +static inline int drm_fb_helper_fb_release(struct fb_info *info, int user) > +{ > + return -ENODEV; > +} > + > static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, > bool suspend) > { > -- > 2.14.2 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel