Merge tag 'media/v4.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

Pull media fixes from Mauro Carvalho Chehab:

- fix a regression on tvp5150 causing failures at input selection and
image glitches

- CEC was moved out of staging for v4.10. Fix some bugs on it while not
too late

- fix a regression on pctv452e caused by VM stack changes

- fix suspend issued with smiapp

- fix a regression on cobalt driver

- fix some warnings and Kconfig issues with some random configs.

* tag 'media/v4.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
[media] s5k4ecgx: select CRC32 helper
[media] dvb: avoid warning in dvb_net
[media] v4l: tvp5150: Don't override output pinmuxing at stream on/off time
[media] v4l: tvp5150: Fix comment regarding output pin muxing
[media] v4l: tvp5150: Reset device at probe time, not in get/set format handlers
[media] pctv452e: move buffer to heap, no mutex
[media] media/cobalt: use pci_irq_allocate_vectors
[media] cec: fix race between configuring and unconfiguring
[media] cec: move cec_report_phys_addr into cec_config_thread_func
[media] cec: replace cec_report_features by cec_fill_msg_report_features
[media] cec: update log_addr[] before finishing configuration
[media] cec: CEC_MSG_GIVE_FEATURES should abort for CEC version < 2
[media] cec: when canceling a message, don't overwrite old status info
[media] cec: fix report_current_latency
[media] smiapp: Make suspend and resume functions __maybe_unused
[media] smiapp: Implement power-on and power-off sequences without runtime PM

+194 -174
+52 -51
drivers/media/cec/cec-adap.c
··· 30 30 31 31 #include "cec-priv.h" 32 32 33 - static int cec_report_features(struct cec_adapter *adap, unsigned int la_idx); 34 - static int cec_report_phys_addr(struct cec_adapter *adap, unsigned int la_idx); 33 + static void cec_fill_msg_report_features(struct cec_adapter *adap, 34 + struct cec_msg *msg, 35 + unsigned int la_idx); 35 36 36 37 /* 37 38 * 400 ms is the time it takes for one 16 byte message to be ··· 289 288 290 289 /* Mark it as an error */ 291 290 data->msg.tx_ts = ktime_get_ns(); 292 - data->msg.tx_status = CEC_TX_STATUS_ERROR | 293 - CEC_TX_STATUS_MAX_RETRIES; 291 + data->msg.tx_status |= CEC_TX_STATUS_ERROR | 292 + CEC_TX_STATUS_MAX_RETRIES; 293 + data->msg.tx_error_cnt++; 294 294 data->attempts = 0; 295 - data->msg.tx_error_cnt = 1; 296 295 /* Queue transmitted message for monitoring purposes */ 297 296 cec_queue_msg_monitor(data->adap, &data->msg, 1); 298 297 ··· 852 851 [CEC_MSG_REQUEST_ARC_TERMINATION] = 2 | DIRECTED, 853 852 [CEC_MSG_TERMINATE_ARC] = 2 | DIRECTED, 854 853 [CEC_MSG_REQUEST_CURRENT_LATENCY] = 4 | BCAST, 855 - [CEC_MSG_REPORT_CURRENT_LATENCY] = 7 | BCAST, 854 + [CEC_MSG_REPORT_CURRENT_LATENCY] = 6 | BCAST, 856 855 [CEC_MSG_CDC_MESSAGE] = 2 | BCAST, 857 856 }; 858 857 ··· 1251 1250 for (i = 1; i < las->num_log_addrs; i++) 1252 1251 las->log_addr[i] = CEC_LOG_ADDR_INVALID; 1253 1252 } 1253 + for (i = las->num_log_addrs; i < CEC_MAX_LOG_ADDRS; i++) 1254 + las->log_addr[i] = CEC_LOG_ADDR_INVALID; 1254 1255 adap->is_configured = true; 1255 1256 adap->is_configuring = false; 1256 1257 cec_post_state_event(adap); 1257 - mutex_unlock(&adap->lock); 1258 1258 1259 + /* 1260 + * Now post the Report Features and Report Physical Address broadcast 1261 + * messages. Note that these are non-blocking transmits, meaning that 1262 + * they are just queued up and once adap->lock is unlocked the main 1263 + * thread will kick in and start transmitting these. 1264 + * 1265 + * If after this function is done (but before one or more of these 1266 + * messages are actually transmitted) the CEC adapter is unconfigured, 1267 + * then any remaining messages will be dropped by the main thread. 1268 + */ 1259 1269 for (i = 0; i < las->num_log_addrs; i++) { 1270 + struct cec_msg msg = {}; 1271 + 1260 1272 if (las->log_addr[i] == CEC_LOG_ADDR_INVALID || 1261 1273 (las->flags & CEC_LOG_ADDRS_FL_CDC_ONLY)) 1262 1274 continue; 1263 1275 1264 - /* 1265 - * Report Features must come first according 1266 - * to CEC 2.0 1267 - */ 1268 - if (las->log_addr[i] != CEC_LOG_ADDR_UNREGISTERED) 1269 - cec_report_features(adap, i); 1270 - cec_report_phys_addr(adap, i); 1276 + msg.msg[0] = (las->log_addr[i] << 4) | 0x0f; 1277 + 1278 + /* Report Features must come first according to CEC 2.0 */ 1279 + if (las->log_addr[i] != CEC_LOG_ADDR_UNREGISTERED && 1280 + adap->log_addrs.cec_version >= CEC_OP_CEC_VERSION_2_0) { 1281 + cec_fill_msg_report_features(adap, &msg, i); 1282 + cec_transmit_msg_fh(adap, &msg, NULL, false); 1283 + } 1284 + 1285 + /* Report Physical Address */ 1286 + cec_msg_report_physical_addr(&msg, adap->phys_addr, 1287 + las->primary_device_type[i]); 1288 + dprintk(2, "config: la %d pa %x.%x.%x.%x\n", 1289 + las->log_addr[i], 1290 + cec_phys_addr_exp(adap->phys_addr)); 1291 + cec_transmit_msg_fh(adap, &msg, NULL, false); 1271 1292 } 1272 - for (i = las->num_log_addrs; i < CEC_MAX_LOG_ADDRS; i++) 1273 - las->log_addr[i] = CEC_LOG_ADDR_INVALID; 1274 - mutex_lock(&adap->lock); 1275 1293 adap->kthread_config = NULL; 1276 - mutex_unlock(&adap->lock); 1277 1294 complete(&adap->config_completion); 1295 + mutex_unlock(&adap->lock); 1278 1296 return 0; 1279 1297 1280 1298 unconfigure: ··· 1546 1526 1547 1527 /* High-level core CEC message handling */ 1548 1528 1549 - /* Transmit the Report Features message */ 1550 - static int cec_report_features(struct cec_adapter *adap, unsigned int la_idx) 1529 + /* Fill in the Report Features message */ 1530 + static void cec_fill_msg_report_features(struct cec_adapter *adap, 1531 + struct cec_msg *msg, 1532 + unsigned int la_idx) 1551 1533 { 1552 - struct cec_msg msg = { }; 1553 1534 const struct cec_log_addrs *las = &adap->log_addrs; 1554 1535 const u8 *features = las->features[la_idx]; 1555 1536 bool op_is_dev_features = false; 1556 1537 unsigned int idx; 1557 1538 1558 - /* This is 2.0 and up only */ 1559 - if (adap->log_addrs.cec_version < CEC_OP_CEC_VERSION_2_0) 1560 - return 0; 1561 - 1562 1539 /* Report Features */ 1563 - msg.msg[0] = (las->log_addr[la_idx] << 4) | 0x0f; 1564 - msg.len = 4; 1565 - msg.msg[1] = CEC_MSG_REPORT_FEATURES; 1566 - msg.msg[2] = adap->log_addrs.cec_version; 1567 - msg.msg[3] = las->all_device_types[la_idx]; 1540 + msg->msg[0] = (las->log_addr[la_idx] << 4) | 0x0f; 1541 + msg->len = 4; 1542 + msg->msg[1] = CEC_MSG_REPORT_FEATURES; 1543 + msg->msg[2] = adap->log_addrs.cec_version; 1544 + msg->msg[3] = las->all_device_types[la_idx]; 1568 1545 1569 1546 /* Write RC Profiles first, then Device Features */ 1570 1547 for (idx = 0; idx < ARRAY_SIZE(las->features[0]); idx++) { 1571 - msg.msg[msg.len++] = features[idx]; 1548 + msg->msg[msg->len++] = features[idx]; 1572 1549 if ((features[idx] & CEC_OP_FEAT_EXT) == 0) { 1573 1550 if (op_is_dev_features) 1574 1551 break; 1575 1552 op_is_dev_features = true; 1576 1553 } 1577 1554 } 1578 - return cec_transmit_msg(adap, &msg, false); 1579 - } 1580 - 1581 - /* Transmit the Report Physical Address message */ 1582 - static int cec_report_phys_addr(struct cec_adapter *adap, unsigned int la_idx) 1583 - { 1584 - const struct cec_log_addrs *las = &adap->log_addrs; 1585 - struct cec_msg msg = { }; 1586 - 1587 - /* Report Physical Address */ 1588 - msg.msg[0] = (las->log_addr[la_idx] << 4) | 0x0f; 1589 - cec_msg_report_physical_addr(&msg, adap->phys_addr, 1590 - las->primary_device_type[la_idx]); 1591 - dprintk(2, "config: la %d pa %x.%x.%x.%x\n", 1592 - las->log_addr[la_idx], 1593 - cec_phys_addr_exp(adap->phys_addr)); 1594 - return cec_transmit_msg(adap, &msg, false); 1595 1555 } 1596 1556 1597 1557 /* Transmit the Feature Abort message */ ··· 1777 1777 } 1778 1778 1779 1779 case CEC_MSG_GIVE_FEATURES: 1780 - if (adap->log_addrs.cec_version >= CEC_OP_CEC_VERSION_2_0) 1781 - return cec_report_features(adap, la_idx); 1782 - return 0; 1780 + if (adap->log_addrs.cec_version < CEC_OP_CEC_VERSION_2_0) 1781 + return cec_feature_abort(adap, msg); 1782 + cec_fill_msg_report_features(adap, &tx_cec_msg, la_idx); 1783 + return cec_transmit_msg(adap, &tx_cec_msg, false); 1783 1784 1784 1785 default: 1785 1786 /*
+5 -10
drivers/media/dvb-core/dvb_net.c
··· 719 719 skb_copy_from_linear_data(h->priv->ule_skb, dest_addr, 720 720 ETH_ALEN); 721 721 skb_pull(h->priv->ule_skb, ETH_ALEN); 722 + } else { 723 + /* dest_addr buffer is only valid if h->priv->ule_dbit == 0 */ 724 + eth_zero_addr(dest_addr); 722 725 } 723 726 724 727 /* Handle ULE Extension Headers. */ ··· 753 750 if (!h->priv->ule_bridged) { 754 751 skb_push(h->priv->ule_skb, ETH_HLEN); 755 752 h->ethh = (struct ethhdr *)h->priv->ule_skb->data; 756 - if (!h->priv->ule_dbit) { 757 - /* 758 - * dest_addr buffer is only valid if 759 - * h->priv->ule_dbit == 0 760 - */ 761 - memcpy(h->ethh->h_dest, dest_addr, ETH_ALEN); 762 - eth_zero_addr(h->ethh->h_source); 763 - } else /* zeroize source and dest */ 764 - memset(h->ethh, 0, ETH_ALEN * 2); 765 - 753 + memcpy(h->ethh->h_dest, dest_addr, ETH_ALEN); 754 + eth_zero_addr(h->ethh->h_source); 766 755 h->ethh->h_proto = htons(h->priv->ule_sndu_type); 767 756 } 768 757 /* else: skb is in correct state; nothing to do. */
+1
drivers/media/i2c/Kconfig
··· 655 655 config VIDEO_S5K4ECGX 656 656 tristate "Samsung S5K4ECGX sensor support" 657 657 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 658 + select CRC32 658 659 ---help--- 659 660 This is a V4L2 sensor-level driver for Samsung S5K4ECGX 5M 660 661 camera sensor with an embedded SoC image signal processor.
+12 -21
drivers/media/i2c/smiapp/smiapp-core.c
··· 2741 2741 * I2C Driver 2742 2742 */ 2743 2743 2744 - #ifdef CONFIG_PM 2745 - 2746 - static int smiapp_suspend(struct device *dev) 2744 + static int __maybe_unused smiapp_suspend(struct device *dev) 2747 2745 { 2748 2746 struct i2c_client *client = to_i2c_client(dev); 2749 2747 struct v4l2_subdev *subdev = i2c_get_clientdata(client); ··· 2766 2768 return 0; 2767 2769 } 2768 2770 2769 - static int smiapp_resume(struct device *dev) 2771 + static int __maybe_unused smiapp_resume(struct device *dev) 2770 2772 { 2771 2773 struct i2c_client *client = to_i2c_client(dev); 2772 2774 struct v4l2_subdev *subdev = i2c_get_clientdata(client); ··· 2780 2782 2781 2783 return rval; 2782 2784 } 2783 - 2784 - #else 2785 - 2786 - #define smiapp_suspend NULL 2787 - #define smiapp_resume NULL 2788 - 2789 - #endif /* CONFIG_PM */ 2790 2785 2791 2786 static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev) 2792 2787 { ··· 2904 2913 if (IS_ERR(sensor->xshutdown)) 2905 2914 return PTR_ERR(sensor->xshutdown); 2906 2915 2907 - pm_runtime_enable(&client->dev); 2908 - 2909 - rval = pm_runtime_get_sync(&client->dev); 2910 - if (rval < 0) { 2911 - rval = -ENODEV; 2912 - goto out_power_off; 2913 - } 2916 + rval = smiapp_power_on(&client->dev); 2917 + if (rval < 0) 2918 + return rval; 2914 2919 2915 2920 rval = smiapp_identify_module(sensor); 2916 2921 if (rval) { ··· 3087 3100 if (rval < 0) 3088 3101 goto out_media_entity_cleanup; 3089 3102 3103 + pm_runtime_set_active(&client->dev); 3104 + pm_runtime_get_noresume(&client->dev); 3105 + pm_runtime_enable(&client->dev); 3090 3106 pm_runtime_set_autosuspend_delay(&client->dev, 1000); 3091 3107 pm_runtime_use_autosuspend(&client->dev); 3092 3108 pm_runtime_put_autosuspend(&client->dev); ··· 3103 3113 smiapp_cleanup(sensor); 3104 3114 3105 3115 out_power_off: 3106 - pm_runtime_put(&client->dev); 3107 - pm_runtime_disable(&client->dev); 3116 + smiapp_power_off(&client->dev); 3108 3117 3109 3118 return rval; 3110 3119 } ··· 3116 3127 3117 3128 v4l2_async_unregister_subdev(subdev); 3118 3129 3119 - pm_runtime_suspend(&client->dev); 3120 3130 pm_runtime_disable(&client->dev); 3131 + if (!pm_runtime_status_suspended(&client->dev)) 3132 + smiapp_power_off(&client->dev); 3133 + pm_runtime_set_suspended(&client->dev); 3121 3134 3122 3135 for (i = 0; i < sensor->ssds_used; i++) { 3123 3136 v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
+34 -20
drivers/media/i2c/tvp5150.c
··· 291 291 tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode); 292 292 tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input); 293 293 294 - /* Svideo should enable YCrCb output and disable GPCL output 295 - * For Composite and TV, it should be the reverse 294 + /* 295 + * Setup the FID/GLCO/VLK/HVLK and INTREQ/GPCL/VBLK output signals. For 296 + * S-Video we output the vertical lock (VLK) signal on FID/GLCO/VLK/HVLK 297 + * and set INTREQ/GPCL/VBLK to logic 0. For composite we output the 298 + * field indicator (FID) signal on FID/GLCO/VLK/HVLK and set 299 + * INTREQ/GPCL/VBLK to logic 1. 296 300 */ 297 301 val = tvp5150_read(sd, TVP5150_MISC_CTL); 298 302 if (val < 0) { ··· 305 301 } 306 302 307 303 if (decoder->input == TVP5150_SVIDEO) 308 - val = (val & ~0x40) | 0x10; 304 + val = (val & ~TVP5150_MISC_CTL_GPCL) | TVP5150_MISC_CTL_HVLK; 309 305 else 310 - val = (val & ~0x10) | 0x40; 306 + val = (val & ~TVP5150_MISC_CTL_HVLK) | TVP5150_MISC_CTL_GPCL; 311 307 tvp5150_write(sd, TVP5150_MISC_CTL, val); 312 308 }; 313 309 ··· 459 455 },{ /* Automatic offset and AGC enabled */ 460 456 TVP5150_ANAL_CHL_CTL, 0x15 461 457 },{ /* Activate YCrCb output 0x9 or 0xd ? */ 462 - TVP5150_MISC_CTL, 0x6f 458 + TVP5150_MISC_CTL, TVP5150_MISC_CTL_GPCL | 459 + TVP5150_MISC_CTL_INTREQ_OE | 460 + TVP5150_MISC_CTL_YCBCR_OE | 461 + TVP5150_MISC_CTL_SYNC_OE | 462 + TVP5150_MISC_CTL_VBLANK | 463 + TVP5150_MISC_CTL_CLOCK_OE, 463 464 },{ /* Activates video std autodetection for all standards */ 464 465 TVP5150_AUTOSW_MSK, 0x0 465 466 },{ /* Default format: 0x47. For 4:2:2: 0x40 */ ··· 870 861 871 862 f = &format->format; 872 863 873 - tvp5150_reset(sd, 0); 874 - 875 864 f->width = decoder->rect.width; 876 865 f->height = decoder->rect.height / 2; 877 866 ··· 1058 1051 static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable) 1059 1052 { 1060 1053 struct tvp5150 *decoder = to_tvp5150(sd); 1061 - /* Output format: 8-bit ITU-R BT.656 with embedded syncs */ 1062 - int val = 0x09; 1054 + int val; 1063 1055 1064 - /* Output format: 8-bit 4:2:2 YUV with discrete sync */ 1065 - if (decoder->mbus_type == V4L2_MBUS_PARALLEL) 1066 - val = 0x0d; 1056 + /* Enable or disable the video output signals. */ 1057 + val = tvp5150_read(sd, TVP5150_MISC_CTL); 1058 + if (val < 0) 1059 + return val; 1067 1060 1068 - /* Initializes TVP5150 to its default values */ 1069 - /* # set PCLK (27MHz) */ 1070 - tvp5150_write(sd, TVP5150_CONF_SHARED_PIN, 0x00); 1061 + val &= ~(TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE | 1062 + TVP5150_MISC_CTL_CLOCK_OE); 1071 1063 1072 - if (enable) 1073 - tvp5150_write(sd, TVP5150_MISC_CTL, val); 1074 - else 1075 - tvp5150_write(sd, TVP5150_MISC_CTL, 0x00); 1064 + if (enable) { 1065 + /* 1066 + * Enable the YCbCr and clock outputs. In discrete sync mode 1067 + * (non-BT.656) additionally enable the the sync outputs. 1068 + */ 1069 + val |= TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_CLOCK_OE; 1070 + if (decoder->mbus_type == V4L2_MBUS_PARALLEL) 1071 + val |= TVP5150_MISC_CTL_SYNC_OE; 1072 + } 1073 + 1074 + tvp5150_write(sd, TVP5150_MISC_CTL, val); 1076 1075 1077 1076 return 0; 1078 1077 } ··· 1537 1524 res = core->hdl.error; 1538 1525 goto err; 1539 1526 } 1540 - v4l2_ctrl_handler_setup(&core->hdl); 1541 1527 1542 1528 /* Default is no cropping */ 1543 1529 core->rect.top = 0; ··· 1546 1534 core->rect.height = TVP5150_V_MAX_OTHERS; 1547 1535 core->rect.left = 0; 1548 1536 core->rect.width = TVP5150_H_MAX; 1537 + 1538 + tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */ 1549 1539 1550 1540 res = v4l2_async_register_subdev(sd); 1551 1541 if (res < 0)
+9
drivers/media/i2c/tvp5150_reg.h
··· 9 9 #define TVP5150_ANAL_CHL_CTL 0x01 /* Analog channel controls */ 10 10 #define TVP5150_OP_MODE_CTL 0x02 /* Operation mode controls */ 11 11 #define TVP5150_MISC_CTL 0x03 /* Miscellaneous controls */ 12 + #define TVP5150_MISC_CTL_VBLK_GPCL BIT(7) 13 + #define TVP5150_MISC_CTL_GPCL BIT(6) 14 + #define TVP5150_MISC_CTL_INTREQ_OE BIT(5) 15 + #define TVP5150_MISC_CTL_HVLK BIT(4) 16 + #define TVP5150_MISC_CTL_YCBCR_OE BIT(3) 17 + #define TVP5150_MISC_CTL_SYNC_OE BIT(2) 18 + #define TVP5150_MISC_CTL_VBLANK BIT(1) 19 + #define TVP5150_MISC_CTL_CLOCK_OE BIT(0) 20 + 12 21 #define TVP5150_AUTOSW_MSK 0x04 /* Autoswitch mask: TVP5150A / TVP5150AM */ 13 22 14 23 /* Reserved 05h */
+2 -6
drivers/media/pci/cobalt/cobalt-driver.c
··· 308 308 static void cobalt_free_msi(struct cobalt *cobalt, struct pci_dev *pci_dev) 309 309 { 310 310 free_irq(pci_dev->irq, (void *)cobalt); 311 - 312 - if (cobalt->msi_enabled) 313 - pci_disable_msi(pci_dev); 311 + pci_free_irq_vectors(pci_dev); 314 312 } 315 313 316 314 static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev, ··· 385 387 from being generated. */ 386 388 cobalt_set_interrupt(cobalt, false); 387 389 388 - if (pci_enable_msi_range(pci_dev, 1, 1) < 1) { 390 + if (pci_alloc_irq_vectors(pci_dev, 1, 1, PCI_IRQ_MSI) < 1) { 389 391 cobalt_err("Could not enable MSI\n"); 390 - cobalt->msi_enabled = false; 391 392 ret = -EIO; 392 393 goto err_release; 393 394 } 394 395 msi_config_show(cobalt, pci_dev); 395 - cobalt->msi_enabled = true; 396 396 397 397 /* Register IRQ */ 398 398 if (request_irq(pci_dev->irq, cobalt_irq_handler, IRQF_SHARED,
-2
drivers/media/pci/cobalt/cobalt-driver.h
··· 287 287 u32 irq_none; 288 288 u32 irq_full_fifo; 289 289 290 - bool msi_enabled; 291 - 292 290 /* omnitek dma */ 293 291 int dma_channels; 294 292 int first_fifo_channel;
+72 -61
drivers/media/usb/dvb-usb/pctv452e.c
··· 97 97 u8 c; /* transaction counter, wraps around... */ 98 98 u8 initialized; /* set to 1 if 0x15 has been sent */ 99 99 u16 last_rc_key; 100 - 101 - unsigned char data[80]; 102 100 }; 103 101 104 102 static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data, 105 103 unsigned int write_len, unsigned int read_len) 106 104 { 107 105 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 106 + u8 *buf; 108 107 u8 id; 109 108 unsigned int rlen; 110 109 int ret; ··· 113 114 return -EIO; 114 115 } 115 116 116 - mutex_lock(&state->ca_mutex); 117 + buf = kmalloc(64, GFP_KERNEL); 118 + if (!buf) 119 + return -ENOMEM; 120 + 117 121 id = state->c++; 118 122 119 - state->data[0] = SYNC_BYTE_OUT; 120 - state->data[1] = id; 121 - state->data[2] = cmd; 122 - state->data[3] = write_len; 123 + buf[0] = SYNC_BYTE_OUT; 124 + buf[1] = id; 125 + buf[2] = cmd; 126 + buf[3] = write_len; 123 127 124 - memcpy(state->data + 4, data, write_len); 128 + memcpy(buf + 4, data, write_len); 125 129 126 130 rlen = (read_len > 0) ? 64 : 0; 127 - ret = dvb_usb_generic_rw(d, state->data, 4 + write_len, 128 - state->data, rlen, /* delay_ms */ 0); 131 + ret = dvb_usb_generic_rw(d, buf, 4 + write_len, 132 + buf, rlen, /* delay_ms */ 0); 129 133 if (0 != ret) 130 134 goto failed; 131 135 132 136 ret = -EIO; 133 - if (SYNC_BYTE_IN != state->data[0] || id != state->data[1]) 137 + if (SYNC_BYTE_IN != buf[0] || id != buf[1]) 134 138 goto failed; 135 139 136 - memcpy(data, state->data + 4, read_len); 140 + memcpy(data, buf + 4, read_len); 137 141 138 - mutex_unlock(&state->ca_mutex); 142 + kfree(buf); 139 143 return 0; 140 144 141 145 failed: 142 146 err("CI error %d; %02X %02X %02X -> %*ph.", 143 - ret, SYNC_BYTE_OUT, id, cmd, 3, state->data); 147 + ret, SYNC_BYTE_OUT, id, cmd, 3, buf); 144 148 145 - mutex_unlock(&state->ca_mutex); 149 + kfree(buf); 146 150 return ret; 147 151 } 148 152 ··· 412 410 u8 *rcv_buf, u8 rcv_len) 413 411 { 414 412 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 413 + u8 *buf; 415 414 u8 id; 416 415 int ret; 417 416 418 - mutex_lock(&state->ca_mutex); 417 + buf = kmalloc(64, GFP_KERNEL); 418 + if (!buf) 419 + return -ENOMEM; 420 + 419 421 id = state->c++; 420 422 421 423 ret = -EINVAL; 422 424 if (snd_len > 64 - 7 || rcv_len > 64 - 7) 423 425 goto failed; 424 426 425 - state->data[0] = SYNC_BYTE_OUT; 426 - state->data[1] = id; 427 - state->data[2] = PCTV_CMD_I2C; 428 - state->data[3] = snd_len + 3; 429 - state->data[4] = addr << 1; 430 - state->data[5] = snd_len; 431 - state->data[6] = rcv_len; 427 + buf[0] = SYNC_BYTE_OUT; 428 + buf[1] = id; 429 + buf[2] = PCTV_CMD_I2C; 430 + buf[3] = snd_len + 3; 431 + buf[4] = addr << 1; 432 + buf[5] = snd_len; 433 + buf[6] = rcv_len; 432 434 433 - memcpy(state->data + 7, snd_buf, snd_len); 435 + memcpy(buf + 7, snd_buf, snd_len); 434 436 435 - ret = dvb_usb_generic_rw(d, state->data, 7 + snd_len, 436 - state->data, /* rcv_len */ 64, 437 + ret = dvb_usb_generic_rw(d, buf, 7 + snd_len, 438 + buf, /* rcv_len */ 64, 437 439 /* delay_ms */ 0); 438 440 if (ret < 0) 439 441 goto failed; 440 442 441 443 /* TT USB protocol error. */ 442 444 ret = -EIO; 443 - if (SYNC_BYTE_IN != state->data[0] || id != state->data[1]) 445 + if (SYNC_BYTE_IN != buf[0] || id != buf[1]) 444 446 goto failed; 445 447 446 448 /* I2C device didn't respond as expected. */ 447 449 ret = -EREMOTEIO; 448 - if (state->data[5] < snd_len || state->data[6] < rcv_len) 450 + if (buf[5] < snd_len || buf[6] < rcv_len) 449 451 goto failed; 450 452 451 - memcpy(rcv_buf, state->data + 7, rcv_len); 452 - mutex_unlock(&state->ca_mutex); 453 + memcpy(rcv_buf, buf + 7, rcv_len); 453 454 455 + kfree(buf); 454 456 return rcv_len; 455 457 456 458 failed: 457 459 err("I2C error %d; %02X %02X %02X %02X %02X -> %*ph", 458 460 ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len, 459 - 7, state->data); 461 + 7, buf); 460 462 461 - mutex_unlock(&state->ca_mutex); 463 + kfree(buf); 462 464 return ret; 463 465 } 464 466 ··· 511 505 static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i) 512 506 { 513 507 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 514 - u8 *rx; 508 + u8 *b0, *rx; 515 509 int ret; 516 510 517 511 info("%s: %d\n", __func__, i); ··· 522 516 if (state->initialized) 523 517 return 0; 524 518 525 - rx = kmalloc(PCTV_ANSWER_LEN, GFP_KERNEL); 526 - if (!rx) 519 + b0 = kmalloc(5 + PCTV_ANSWER_LEN, GFP_KERNEL); 520 + if (!b0) 527 521 return -ENOMEM; 528 522 529 - mutex_lock(&state->ca_mutex); 523 + rx = b0 + 5; 524 + 530 525 /* hmm where shoud this should go? */ 531 526 ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE); 532 527 if (ret != 0) ··· 535 528 __func__, ret); 536 529 537 530 /* this is a one-time initialization, dont know where to put */ 538 - state->data[0] = 0xaa; 539 - state->data[1] = state->c++; 540 - state->data[2] = PCTV_CMD_RESET; 541 - state->data[3] = 1; 542 - state->data[4] = 0; 531 + b0[0] = 0xaa; 532 + b0[1] = state->c++; 533 + b0[2] = PCTV_CMD_RESET; 534 + b0[3] = 1; 535 + b0[4] = 0; 543 536 /* reset board */ 544 - ret = dvb_usb_generic_rw(d, state->data, 5, rx, PCTV_ANSWER_LEN, 0); 537 + ret = dvb_usb_generic_rw(d, b0, 5, rx, PCTV_ANSWER_LEN, 0); 545 538 if (ret) 546 539 goto ret; 547 540 548 - state->data[1] = state->c++; 549 - state->data[4] = 1; 541 + b0[1] = state->c++; 542 + b0[4] = 1; 550 543 /* reset board (again?) */ 551 - ret = dvb_usb_generic_rw(d, state->data, 5, rx, PCTV_ANSWER_LEN, 0); 544 + ret = dvb_usb_generic_rw(d, b0, 5, rx, PCTV_ANSWER_LEN, 0); 552 545 if (ret) 553 546 goto ret; 554 547 555 548 state->initialized = 1; 556 549 557 550 ret: 558 - mutex_unlock(&state->ca_mutex); 559 - kfree(rx); 551 + kfree(b0); 560 552 return ret; 561 553 } 562 554 563 555 static int pctv452e_rc_query(struct dvb_usb_device *d) 564 556 { 565 557 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 558 + u8 *b, *rx; 566 559 int ret, i; 567 560 u8 id; 568 561 569 - mutex_lock(&state->ca_mutex); 562 + b = kmalloc(CMD_BUFFER_SIZE + PCTV_ANSWER_LEN, GFP_KERNEL); 563 + if (!b) 564 + return -ENOMEM; 565 + 566 + rx = b + CMD_BUFFER_SIZE; 567 + 570 568 id = state->c++; 571 569 572 570 /* prepare command header */ 573 - state->data[0] = SYNC_BYTE_OUT; 574 - state->data[1] = id; 575 - state->data[2] = PCTV_CMD_IR; 576 - state->data[3] = 0; 571 + b[0] = SYNC_BYTE_OUT; 572 + b[1] = id; 573 + b[2] = PCTV_CMD_IR; 574 + b[3] = 0; 577 575 578 576 /* send ir request */ 579 - ret = dvb_usb_generic_rw(d, state->data, 4, 580 - state->data, PCTV_ANSWER_LEN, 0); 577 + ret = dvb_usb_generic_rw(d, b, 4, rx, PCTV_ANSWER_LEN, 0); 581 578 if (ret != 0) 582 579 goto ret; 583 580 584 581 if (debug > 3) { 585 - info("%s: read: %2d: %*ph: ", __func__, ret, 3, state->data); 586 - for (i = 0; (i < state->data[3]) && ((i + 3) < PCTV_ANSWER_LEN); i++) 587 - info(" %02x", state->data[i + 3]); 582 + info("%s: read: %2d: %*ph: ", __func__, ret, 3, rx); 583 + for (i = 0; (i < rx[3]) && ((i+3) < PCTV_ANSWER_LEN); i++) 584 + info(" %02x", rx[i+3]); 588 585 589 586 info("\n"); 590 587 } 591 588 592 - if ((state->data[3] == 9) && (state->data[12] & 0x01)) { 589 + if ((rx[3] == 9) && (rx[12] & 0x01)) { 593 590 /* got a "press" event */ 594 - state->last_rc_key = RC_SCANCODE_RC5(state->data[7], state->data[6]); 591 + state->last_rc_key = RC_SCANCODE_RC5(rx[7], rx[6]); 595 592 if (debug > 2) 596 593 info("%s: cmd=0x%02x sys=0x%02x\n", 597 - __func__, state->data[6], state->data[7]); 594 + __func__, rx[6], rx[7]); 598 595 599 596 rc_keydown(d->rc_dev, RC_TYPE_RC5, state->last_rc_key, 0); 600 597 } else if (state->last_rc_key) { ··· 606 595 state->last_rc_key = 0; 607 596 } 608 597 ret: 609 - mutex_unlock(&state->ca_mutex); 598 + kfree(b); 610 599 return ret; 611 600 } 612 601
+7 -3
include/uapi/linux/cec-funcs.h
··· 1665 1665 __u8 audio_out_compensated, 1666 1666 __u8 audio_out_delay) 1667 1667 { 1668 - msg->len = 7; 1668 + msg->len = 6; 1669 1669 msg->msg[0] |= 0xf; /* broadcast */ 1670 1670 msg->msg[1] = CEC_MSG_REPORT_CURRENT_LATENCY; 1671 1671 msg->msg[2] = phys_addr >> 8; 1672 1672 msg->msg[3] = phys_addr & 0xff; 1673 1673 msg->msg[4] = video_latency; 1674 1674 msg->msg[5] = (low_latency_mode << 2) | audio_out_compensated; 1675 - msg->msg[6] = audio_out_delay; 1675 + if (audio_out_compensated == 3) 1676 + msg->msg[msg->len++] = audio_out_delay; 1676 1677 } 1677 1678 1678 1679 static inline void cec_ops_report_current_latency(const struct cec_msg *msg, ··· 1687 1686 *video_latency = msg->msg[4]; 1688 1687 *low_latency_mode = (msg->msg[5] >> 2) & 1; 1689 1688 *audio_out_compensated = msg->msg[5] & 3; 1690 - *audio_out_delay = msg->msg[6]; 1689 + if (*audio_out_compensated == 3 && msg->len >= 7) 1690 + *audio_out_delay = msg->msg[6]; 1691 + else 1692 + *audio_out_delay = 0; 1691 1693 } 1692 1694 1693 1695 static inline void cec_msg_request_current_latency(struct cec_msg *msg,