diff options
author | Dmitry Lifshitz <lifshitz@compulab.co.il> | 2012-06-13 06:49:30 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-05 13:22:12 -0400 |
commit | 8cd0d4caa1b4e8f150f9c63bd2be60518381d3f1 (patch) | |
tree | 114a97354394f1070fa11224c42517c3fe59d487 /drivers/media/video/tvp5150.c | |
parent | 800728715cdd3b75fa039c172d57d9e51ac2e0d9 (diff) |
[media] tvp5150: fix kernel crash if chip is unavailable
tvp5150 driver probe function doesn't check if the chip is present.
Thus the driver can be loaded without having a device.
This is dangerous and can cause kernel crash like this:
Kernel BUG at c03c0964 [verbose debug info unavailable]
Internal error: Oops - BUG: 0 [#1] PREEMPT ARM
Modules linked in:
CPU: 0 Tainted: G W (3.4.0-cm-t3730+ #2)
PC is at media_entity_create_link+0xe4/0xf4
LR is at isp_register_entities+0x228/0x2f4
pc : [<c03c0964>] lr : [<c03f3b30>] psr: 60000013
sp : cf02de50 ip : 00000000 fp : c079405c
r10: 00000000 r9 : 00000000 r8 : cf33c800
r7 : c0794834 r6 : 00000000 r5 : 00000000 r4 : cf365b48
r3 : 00000000 r2 : cf365b48 r1 : 00000000 r0 : cf33c800
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: 10c5387d Table: 80004019 DAC: 00000015
Process swapper (pid: 1, stack limit = 0xcf02c2f0)
Stack: (0xcf02de50 to 0xcf02e000)
de40: cf360000 cf366f28 cf366218 c0794834
de60: cf365b48 00000000 cf33c800 c03f3b30 00000000 00000000 cf360890 cf3668a0
de80: 00000003 cf360000 c0785a58 00000000 cf360528 00000000 00000000 00003fff
dea0: cf360500 c03f4cdc c06cc1f4 cf360000 c0785a58 c0d27808 c07d55ec c0785a58
dec0: c031f0e0 c07d55ec c0776900 000000bb 00000000 c032040c c03203f4 c031ef0c
dee0: c0785a58 c07d55ec c0785a8c c031f0e0 c075e670 c031f0c8 cf02deb8 c0785a58
df00: c07d55ec c031f174 c07d55ec 00000000 cf02df18 c031d7a0 cf01d4a8 cf068b10
df20: 00000000 c07d55ec c07c74d0 cf34bcc0 00000000 c031ded8 c0672340 c054cd38
df40: 00000000 c07e68c0 c07d55ec 00000000 00000000 c075e670 c0776900 000000bb
df60: 00000000 c031f770 c07e68c0 00000007 c07e68c0 00000000 c075e670 c0008790
df80: 000000bb 00000006 00000006 c066e650 cf02dfa4 c07689b8 c07689b8 00000007
dfa0: c07e68c0 c073f2e8 c07689c0 000000bb 00000000 c073f2bc 00000006 00000006
dfc0: c073f2e8 00000000 c077649c c077649c c00150cc 00000013 00000000 00000000
dfe0: 00000000 c073f3cc cf02dfe8 00000000 c073f368 c00150cc 00000000 00000000
[<c03c0964>] (media_entity_create_link+0xe4/0xf4) from [<c03f3b30>] (isp_register_entities+0x228/0x2f4)
[<c03f3b30>] (isp_register_entities+0x228/0x2f4) from [<c03f4cdc>] (isp_probe+0x7ac/0x9b8)
[<c03f4cdc>] (isp_probe+0x7ac/0x9b8) from [<c032040c>] (platform_drv_probe+0x18/0x1c)
[<c032040c>] (platform_drv_probe+0x18/0x1c) from [<c031ef0c>] (really_probe+0x64/0x1d8)
[<c031ef0c>] (really_probe+0x64/0x1d8) from [<c031f0c8>] (driver_probe_device+0x48/0x60)
[<c031f0c8>] (driver_probe_device+0x48/0x60) from [<c031f174>] (__driver_attach+0x94/0x98)
[<c031f174>] (__driver_attach+0x94/0x98) from [<c031d7a0>] (bus_for_each_dev+0x54/0x80)
[<c031d7a0>] (bus_for_each_dev+0x54/0x80) from [<c031ded8>] (bus_add_driver+0xac/0x2a8)
[<c031ded8>] (bus_add_driver+0xac/0x2a8) from [<c031f770>] (driver_register+0x78/0x180)
[<c031f770>] (driver_register+0x78/0x180) from [<c0008790>] (do_one_initcall+0x34/0x184)
[<c0008790>] (do_one_initcall+0x34/0x184) from [<c073f2bc>] (do_basic_setup+0x9c/0xc8)
[<c073f2bc>] (do_basic_setup+0x9c/0xc8) from [<c073f3cc>] (kernel_init+0x64/0xec)
[<c073f3cc>] (kernel_init+0x64/0xec) from [<c00150cc>] (kernel_thread_exit+0x0/0x8)
Code: e1c812b6 e8bd87f0 e7f001f2 eafffffe (e7f001f2)
---[ end trace 3ed3c618b26ff3e8 ]---
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
This patch fixes the tvp5150_read() function to return an error in case
the I2C transaction fails.
tvp5150_probe() and other relevant driver callbacks changed to check the
status of the I2C read operations.
In case of a read error throw an error message with v4l2_err()
instead of v4l2_dbg().
[mchehab@redhat.com: Fix a small typo breaking compilation]
Signed-off-by: Dmitry Lifshitz <lifshitz@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tvp5150.c')
-rw-r--r-- | drivers/media/video/tvp5150.c | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c index b7867427e5c4..0d897cb1774a 100644 --- a/drivers/media/video/tvp5150.c +++ b/drivers/media/video/tvp5150.c | |||
@@ -61,13 +61,20 @@ static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr) | |||
61 | int rc; | 61 | int rc; |
62 | 62 | ||
63 | buffer[0] = addr; | 63 | buffer[0] = addr; |
64 | if (1 != (rc = i2c_master_send(c, buffer, 1))) | 64 | |
65 | v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc); | 65 | rc = i2c_master_send(c, buffer, 1); |
66 | if (rc < 0) { | ||
67 | v4l2_err(sd, "i2c i/o error: rc == %d (should be 1)\n", rc); | ||
68 | return rc; | ||
69 | } | ||
66 | 70 | ||
67 | msleep(10); | 71 | msleep(10); |
68 | 72 | ||
69 | if (1 != (rc = i2c_master_recv(c, buffer, 1))) | 73 | rc = i2c_master_recv(c, buffer, 1); |
70 | v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc); | 74 | if (rc < 0) { |
75 | v4l2_err(sd, "i2c i/o error: rc == %d (should be 1)\n", rc); | ||
76 | return rc; | ||
77 | } | ||
71 | 78 | ||
72 | v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); | 79 | v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); |
73 | 80 | ||
@@ -279,6 +286,11 @@ static inline void tvp5150_selmux(struct v4l2_subdev *sd) | |||
279 | * For Composite and TV, it should be the reverse | 286 | * For Composite and TV, it should be the reverse |
280 | */ | 287 | */ |
281 | val = tvp5150_read(sd, TVP5150_MISC_CTL); | 288 | val = tvp5150_read(sd, TVP5150_MISC_CTL); |
289 | if (val < 0) { | ||
290 | v4l2_err(sd, "%s: failed with error = %d\n", __func__, val); | ||
291 | return; | ||
292 | } | ||
293 | |||
282 | if (decoder->input == TVP5150_SVIDEO) | 294 | if (decoder->input == TVP5150_SVIDEO) |
283 | val = (val & ~0x40) | 0x10; | 295 | val = (val & ~0x40) | 0x10; |
284 | else | 296 | else |
@@ -676,6 +688,7 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd, | |||
676 | v4l2_std_id std = decoder->norm; | 688 | v4l2_std_id std = decoder->norm; |
677 | u8 reg; | 689 | u8 reg; |
678 | int pos, type = 0; | 690 | int pos, type = 0; |
691 | int i, ret = 0; | ||
679 | 692 | ||
680 | if (std == V4L2_STD_ALL) { | 693 | if (std == V4L2_STD_ALL) { |
681 | v4l2_err(sd, "VBI can't be configured without knowing number of lines\n"); | 694 | v4l2_err(sd, "VBI can't be configured without knowing number of lines\n"); |
@@ -690,13 +703,17 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd, | |||
690 | 703 | ||
691 | reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; | 704 | reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; |
692 | 705 | ||
693 | pos = tvp5150_read(sd, reg) & 0x0f; | 706 | for (i = 0; i <= 1; i++) { |
694 | if (pos < 0x0f) | 707 | ret = tvp5150_read(sd, reg + i); |
695 | type = regs[pos].type.vbi_type; | 708 | if (ret < 0) { |
696 | 709 | v4l2_err(sd, "%s: failed with error = %d\n", | |
697 | pos = tvp5150_read(sd, reg + 1) & 0x0f; | 710 | __func__, ret); |
698 | if (pos < 0x0f) | 711 | return 0; |
699 | type |= regs[pos].type.vbi_type; | 712 | } |
713 | pos = ret & 0x0f; | ||
714 | if (pos < 0x0f) | ||
715 | type |= regs[pos].type.vbi_type; | ||
716 | } | ||
700 | 717 | ||
701 | return type; | 718 | return type; |
702 | } | 719 | } |
@@ -1031,13 +1048,21 @@ static int tvp5150_g_chip_ident(struct v4l2_subdev *sd, | |||
1031 | #ifdef CONFIG_VIDEO_ADV_DEBUG | 1048 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
1032 | static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) | 1049 | static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) |
1033 | { | 1050 | { |
1051 | int res; | ||
1052 | |||
1034 | struct i2c_client *client = v4l2_get_subdevdata(sd); | 1053 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
1035 | 1054 | ||
1036 | if (!v4l2_chip_match_i2c_client(client, ®->match)) | 1055 | if (!v4l2_chip_match_i2c_client(client, ®->match)) |
1037 | return -EINVAL; | 1056 | return -EINVAL; |
1038 | if (!capable(CAP_SYS_ADMIN)) | 1057 | if (!capable(CAP_SYS_ADMIN)) |
1039 | return -EPERM; | 1058 | return -EPERM; |
1040 | reg->val = tvp5150_read(sd, reg->reg & 0xff); | 1059 | res = tvp5150_read(sd, reg->reg & 0xff); |
1060 | if (res < 0) { | ||
1061 | v4l2_err(sd, "%s: failed with error = %d\n", __func__, res); | ||
1062 | return res; | ||
1063 | } | ||
1064 | |||
1065 | reg->val = res; | ||
1041 | reg->size = 1; | 1066 | reg->size = 1; |
1042 | return 0; | 1067 | return 0; |
1043 | } | 1068 | } |
@@ -1126,7 +1151,8 @@ static int tvp5150_probe(struct i2c_client *c, | |||
1126 | { | 1151 | { |
1127 | struct tvp5150 *core; | 1152 | struct tvp5150 *core; |
1128 | struct v4l2_subdev *sd; | 1153 | struct v4l2_subdev *sd; |
1129 | u8 msb_id, lsb_id, msb_rom, lsb_rom; | 1154 | int tvp5150_id[4]; |
1155 | int i, res; | ||
1130 | 1156 | ||
1131 | /* Check if the adapter supports the needed features */ | 1157 | /* Check if the adapter supports the needed features */ |
1132 | if (!i2c_check_functionality(c->adapter, | 1158 | if (!i2c_check_functionality(c->adapter, |
@@ -1139,26 +1165,37 @@ static int tvp5150_probe(struct i2c_client *c, | |||
1139 | } | 1165 | } |
1140 | sd = &core->sd; | 1166 | sd = &core->sd; |
1141 | v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); | 1167 | v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); |
1168 | |||
1169 | /* | ||
1170 | * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID, | ||
1171 | * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER | ||
1172 | */ | ||
1173 | for (i = 0; i < 4; i++) { | ||
1174 | res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i); | ||
1175 | if (res < 0) | ||
1176 | goto free_core; | ||
1177 | tvp5150_id[i] = res; | ||
1178 | } | ||
1179 | |||
1142 | v4l_info(c, "chip found @ 0x%02x (%s)\n", | 1180 | v4l_info(c, "chip found @ 0x%02x (%s)\n", |
1143 | c->addr << 1, c->adapter->name); | 1181 | c->addr << 1, c->adapter->name); |
1144 | 1182 | ||
1145 | msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID); | 1183 | if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */ |
1146 | lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID); | 1184 | v4l2_info(sd, "tvp%02x%02xam1 detected.\n", |
1147 | msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER); | 1185 | tvp5150_id[0], tvp5150_id[1]); |
1148 | lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER); | ||
1149 | |||
1150 | if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */ | ||
1151 | v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id); | ||
1152 | 1186 | ||
1153 | /* ITU-T BT.656.4 timing */ | 1187 | /* ITU-T BT.656.4 timing */ |
1154 | tvp5150_write(sd, TVP5150_REV_SELECT, 0); | 1188 | tvp5150_write(sd, TVP5150_REV_SELECT, 0); |
1155 | } else { | 1189 | } else { |
1156 | if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */ | 1190 | /* Is TVP5150A */ |
1157 | v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id); | 1191 | if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) { |
1192 | v4l2_info(sd, "tvp%02x%02xa detected.\n", | ||
1193 | tvp5150_id[2], tvp5150_id[3]); | ||
1158 | } else { | 1194 | } else { |
1159 | v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n", | 1195 | v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n", |
1160 | msb_id, lsb_id); | 1196 | tvp5150_id[2], tvp5150_id[3]); |
1161 | v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom); | 1197 | v4l2_info(sd, "*** Rom ver is %d.%d\n", |
1198 | tvp5150_id[2], tvp5150_id[3]); | ||
1162 | } | 1199 | } |
1163 | } | 1200 | } |
1164 | 1201 | ||
@@ -1177,11 +1214,9 @@ static int tvp5150_probe(struct i2c_client *c, | |||
1177 | V4L2_CID_HUE, -128, 127, 1, 0); | 1214 | V4L2_CID_HUE, -128, 127, 1, 0); |
1178 | sd->ctrl_handler = &core->hdl; | 1215 | sd->ctrl_handler = &core->hdl; |
1179 | if (core->hdl.error) { | 1216 | if (core->hdl.error) { |
1180 | int err = core->hdl.error; | 1217 | res = core->hdl.error; |
1181 | |||
1182 | v4l2_ctrl_handler_free(&core->hdl); | 1218 | v4l2_ctrl_handler_free(&core->hdl); |
1183 | kfree(core); | 1219 | goto free_core; |
1184 | return err; | ||
1185 | } | 1220 | } |
1186 | v4l2_ctrl_handler_setup(&core->hdl); | 1221 | v4l2_ctrl_handler_setup(&core->hdl); |
1187 | 1222 | ||
@@ -1197,6 +1232,10 @@ static int tvp5150_probe(struct i2c_client *c, | |||
1197 | if (debug > 1) | 1232 | if (debug > 1) |
1198 | tvp5150_log_status(sd); | 1233 | tvp5150_log_status(sd); |
1199 | return 0; | 1234 | return 0; |
1235 | |||
1236 | free_core: | ||
1237 | kfree(core); | ||
1238 | return res; | ||
1200 | } | 1239 | } |
1201 | 1240 | ||
1202 | static int tvp5150_remove(struct i2c_client *c) | 1241 | static int tvp5150_remove(struct i2c_client *c) |