drm_sysfb.c 866 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/export.h>
  3. #include <linux/limits.h>
  4. #include <linux/minmax.h>
  5. #include <linux/module.h>
  6. #include <drm/drm_print.h>
  7. #include "drm_sysfb_helper.h"
  8. int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name,
  9. u64 value, u32 max)
  10. {
  11. if (value > min(max, INT_MAX)) {
  12. drm_warn(dev, "%s of %llu exceeds maximum of %u\n", name, value, max);
  13. return -EINVAL;
  14. }
  15. return value;
  16. }
  17. EXPORT_SYMBOL(drm_sysfb_get_validated_int);
  18. int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name,
  19. u64 value, u32 max)
  20. {
  21. if (!value) {
  22. drm_warn(dev, "%s of 0 not allowed\n", name);
  23. return -EINVAL;
  24. }
  25. return drm_sysfb_get_validated_int(dev, name, value, max);
  26. }
  27. EXPORT_SYMBOL(drm_sysfb_get_validated_int0);
  28. MODULE_DESCRIPTION("Helpers for DRM sysfb drivers");
  29. MODULE_LICENSE("GPL");