소스 검색

[media] v4l: Do not allow re-registering sub-devices

Albeit not prohibited explicitly, re-registering sub-devices generated a
big, loud warning which quite likely soon was followed by a crash. What
followed was re-initialising a media entity, driver's registered() callback
being called and re-adding a list entry to a list.

Prevent this by returning an error if a sub-device is already registered.

[mchehab@s-opensource.com: reorder logic to check if !sd before dereferencing it]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Sakari Ailus 9 년 전
부모
커밋
fc49071766
1개의 변경된 파일1개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 4
      drivers/media/v4l2-core/v4l2-device.c

+ 1 - 4
drivers/media/v4l2-core/v4l2-device.c

@@ -160,12 +160,9 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
 	int err;
 	int err;
 
 
 	/* Check for valid input */
 	/* Check for valid input */
-	if (v4l2_dev == NULL || sd == NULL || !sd->name[0])
+	if (!v4l2_dev || !sd || sd->v4l2_dev || !sd->name[0])
 		return -EINVAL;
 		return -EINVAL;
 
 
-	/* Warn if we apparently re-register a subdev */
-	WARN_ON(sd->v4l2_dev != NULL);
-
 	/*
 	/*
 	 * The reason to acquire the module here is to avoid unloading
 	 * The reason to acquire the module here is to avoid unloading
 	 * a module of sub-device which is registered to a media
 	 * a module of sub-device which is registered to a media