hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/gpu/drm/vc4/vc4_perfmon.c
....@@ -100,11 +100,17 @@
100100 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
101101 struct drm_file *file_priv)
102102 {
103
+ struct vc4_dev *vc4 = to_vc4_dev(dev);
103104 struct vc4_file *vc4file = file_priv->driver_priv;
104105 struct drm_vc4_perfmon_create *req = data;
105106 struct vc4_perfmon *perfmon;
106107 unsigned int i;
107108 int ret;
109
+
110
+ if (!vc4->v3d) {
111
+ DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
112
+ return -ENODEV;
113
+ }
108114
109115 /* Number of monitored counters cannot exceed HW limits. */
110116 if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
....@@ -117,7 +123,7 @@
117123 return -EINVAL;
118124 }
119125
120
- perfmon = kzalloc(sizeof(*perfmon) + (req->ncounters * sizeof(u64)),
126
+ perfmon = kzalloc(struct_size(perfmon, counters, req->ncounters),
121127 GFP_KERNEL);
122128 if (!perfmon)
123129 return -ENOMEM;
....@@ -146,9 +152,15 @@
146152 int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
147153 struct drm_file *file_priv)
148154 {
155
+ struct vc4_dev *vc4 = to_vc4_dev(dev);
149156 struct vc4_file *vc4file = file_priv->driver_priv;
150157 struct drm_vc4_perfmon_destroy *req = data;
151158 struct vc4_perfmon *perfmon;
159
+
160
+ if (!vc4->v3d) {
161
+ DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
162
+ return -ENODEV;
163
+ }
152164
153165 mutex_lock(&vc4file->perfmon.lock);
154166 perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
....@@ -164,11 +176,17 @@
164176 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
165177 struct drm_file *file_priv)
166178 {
179
+ struct vc4_dev *vc4 = to_vc4_dev(dev);
167180 struct vc4_file *vc4file = file_priv->driver_priv;
168181 struct drm_vc4_perfmon_get_values *req = data;
169182 struct vc4_perfmon *perfmon;
170183 int ret;
171184
185
+ if (!vc4->v3d) {
186
+ DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
187
+ return -ENODEV;
188
+ }
189
+
172190 mutex_lock(&vc4file->perfmon.lock);
173191 perfmon = idr_find(&vc4file->perfmon.idr, req->id);
174192 vc4_perfmon_get(perfmon);