hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/lib/test_kmod.c
....@@ -204,7 +204,7 @@
204204 case TEST_KMOD_DRIVER:
205205 break;
206206 case TEST_KMOD_FS_TYPE:
207
- if (info && info->fs_sync && info->fs_sync->owner)
207
+ if (info->fs_sync && info->fs_sync->owner)
208208 module_put(info->fs_sync->owner);
209209 break;
210210 default:
....@@ -877,20 +877,17 @@
877877 int (*test_sync)(struct kmod_test_device *test_dev))
878878 {
879879 int ret;
880
- unsigned long new;
880
+ unsigned int val;
881881 unsigned int old_val;
882882
883
- ret = kstrtoul(buf, 10, &new);
883
+ ret = kstrtouint(buf, 10, &val);
884884 if (ret)
885885 return ret;
886
-
887
- if (new > UINT_MAX)
888
- return -EINVAL;
889886
890887 mutex_lock(&test_dev->config_mutex);
891888
892889 old_val = *config;
893
- *(unsigned int *)config = new;
890
+ *(unsigned int *)config = val;
894891
895892 ret = test_sync(test_dev);
896893 if (ret) {
....@@ -914,18 +911,18 @@
914911 unsigned int min,
915912 unsigned int max)
916913 {
914
+ unsigned int val;
917915 int ret;
918
- unsigned long new;
919916
920
- ret = kstrtoul(buf, 10, &new);
917
+ ret = kstrtouint(buf, 10, &val);
921918 if (ret)
922919 return ret;
923920
924
- if (new < min || new > max)
921
+ if (val < min || val > max)
925922 return -EINVAL;
926923
927924 mutex_lock(&test_dev->config_mutex);
928
- *config = new;
925
+ *config = val;
929926 mutex_unlock(&test_dev->config_mutex);
930927
931928 /* Always return full write size even if we didn't consume all */
....@@ -936,18 +933,15 @@
936933 const char *buf, size_t size,
937934 int *config)
938935 {
936
+ int val;
939937 int ret;
940
- long new;
941938
942
- ret = kstrtol(buf, 10, &new);
939
+ ret = kstrtoint(buf, 10, &val);
943940 if (ret)
944941 return ret;
945942
946
- if (new < INT_MIN || new > INT_MAX)
947
- return -EINVAL;
948
-
949943 mutex_lock(&test_dev->config_mutex);
950
- *config = new;
944
+ *config = val;
951945 mutex_unlock(&test_dev->config_mutex);
952946 /* Always return full write size even if we didn't consume all */
953947 return size;
....@@ -1155,6 +1149,7 @@
11551149 if (ret) {
11561150 pr_err("could not register misc device: %d\n", ret);
11571151 free_test_dev_kmod(test_dev);
1152
+ test_dev = NULL;
11581153 goto out;
11591154 }
11601155