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