iommu/amd: Fix error handling for pdev_pri_ats_enable()
Subsystems (7)
Sasha Levin
maintainerPATCH 1/16 iommu/amd: Fix error handling for pdev_pri_ats_enable()
From: Vasant Hegde <[email protected]>
[ Upstream commit 080920e52148b4fbbf9360d5345fdcd7846e4841 ]
Current code throws kernel warning if it fails to enable pasid/pri [1]. Do not call pci_disable_[pasid/pri] if pci_enable_[pasid/pri] failed.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
--- drivers/iommu/amd_iommu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iommu/amd_iommu.c +7 -5
@@ -2059,17 +2059,17 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev)/* Only allow access to user-accessible pages */ ret =pci_enable_pasid (pdev,0 );if (ret) - goto out_err; +return ret;/* First reset the PRI state of the device */ ret =pci_reset_pri (pdev);if (ret) - goto out_err; + goto out_err_pasid;/* Enable PRI */ ret =pci_enable_pri (pdev, reqs);if (ret) - goto out_err; + goto out_err_pasid;if (reset_enable) { ret =pri_reset_while_enabled (pdev);
@@ -2079,12 +2079,14 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) ret =pci_enable_ats (pdev,PAGE_SHIFT );if (ret) - goto out_err; + goto out_err_pri;return 0 ; -out_err: +out_err_pri:pci_disable_pri (pdev); + +out_err_pasid:pci_disable_pasid (pdev);return ret;
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 2/16 media: uvcvideo: Handle cameras with invalid descriptors
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 41ddb251c68ac75c101d3a50a68c4629c9055e4c ]
If the source entity does not contain any pads, do not create a link.
--- drivers/media/usb/uvc/uvc_entity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_entity.c +1 -1
@@ -42,7 +42,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,continue ; remote =uvc_entity_by_id (chain->dev, entity->baSourceID[i]); -if (remote ==NULL ) +if (remote ==NULL || remote->num_pads ==0 )return -EINVAL ; source = (UVC_ENTITY_TYPE (remote) ==UVC_TT_STREAMING )
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 3/16 media: uvcvideo: Handle errors from calls to usb_string
In reply to Sasha LevinFrom: Guenter Roeck <[email protected]>
[ Upstream commit 4867bb590ae445bcfaa711a86b603c97e94574b3 ]
On a Webcam from Quanta, we see the following error.
usb 3-5: New USB device found, idVendor=0408, idProduct=30d2, bcdDevice= 0.03 usb 3-5: New USB device strings: Mfr=3, Product=1, SerialNumber=2 usb 3-5: Product: USB2.0 HD UVC WebCam
usb 3-5: Manufacturer: Quanta
usb 3-5: SerialNumber: 0x0001
...
uvcvideo: Found UVC 1.10 device USB2.0 HD UVC WebCam (0408:30d2)
uvcvideo: Failed to initialize entity for entity 5
uvcvideo: Failed to register entities (-22).
The Webcam reports an entity of type UVC_VC_EXTENSION_UNIT. It reports a string index of '7' associated with that entity. The attempt to read that string from the camera fails with error -32 (-EPIPE). usb_string() returns that error, but it is ignored. As result, the entity name is empty. This later causes v4l2_device_register_subdev() to return -EINVAL, and no entities are registered as result.
While this appears to be a firmware problem with the camera, the kernel should still handle the situation gracefully. To do that, check the return value from usb_string(). If it reports an error, assign the entity's default name.
--- drivers/media/usb/uvc/uvc_driver.c | 48 ++++++++++++------------------ 1 file changed, 19 insertions(+), 29 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +19 -29
@@ -1033,10 +1033,8 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, + n;memcpy (unit->extension.bmControls, &buffer[23 +p],2 *n); -if (buffer[24 +p+2 *n] !=0 ) -usb_string (udev, buffer[24 +p+2 *n], unit->name, -sizeof (unit->name)); -else +if (buffer[24 +p+2 *n] ==0 || +usb_string (udev, buffer[24 +p+2 *n], unit->name,sizeof (unit->name)) <0 )sprintf (unit->name,"Extension %u" , buffer[3 ]);list_add_tail (&unit->list, &dev->entities);
@@ -1161,15 +1159,15 @@ static int uvc_parse_standard_control(struct uvc_device *dev,memcpy (term->media.bmTransportModes, &buffer[10 +n], p); } -if (buffer[7 ] !=0 ) -usb_string (udev, buffer[7 ], term->name, -sizeof (term->name)); -else if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) -sprintf (term->name,"Camera %u" , buffer[3 ]); -else if (UVC_ENTITY_TYPE (term) ==UVC_ITT_MEDIA_TRANSPORT_INPUT ) -sprintf (term->name,"Media %u" , buffer[3 ]); -else -sprintf (term->name,"Input %u" , buffer[3 ]); +if (buffer[7 ] ==0 || +usb_string (udev, buffer[7 ], term->name,sizeof (term->name)) <0 ) { +if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) +sprintf (term->name,"Camera %u" , buffer[3 ]); +if (UVC_ENTITY_TYPE (term) ==UVC_ITT_MEDIA_TRANSPORT_INPUT ) +sprintf (term->name,"Media %u" , buffer[3 ]); +else +sprintf (term->name,"Input %u" , buffer[3 ]); + }list_add_tail (&term->list, &dev->entities);break ;
@@ -1201,10 +1199,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev,memcpy (term->baSourceID, &buffer[7 ],1 ); -if (buffer[8 ] !=0 ) -usb_string (udev, buffer[8 ], term->name, -sizeof (term->name)); -else +if (buffer[8 ] ==0 || +usb_string (udev, buffer[8 ], term->name,sizeof (term->name)) <0 )sprintf (term->name,"Output %u" , buffer[3 ]);list_add_tail (&term->list, &dev->entities);
@@ -1226,10 +1222,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev,memcpy (unit->baSourceID, &buffer[5 ], p); -if (buffer[5 +p] !=0 ) -usb_string (udev, buffer[5 +p], unit->name, -sizeof (unit->name)); -else +if (buffer[5 +p] ==0 || +usb_string (udev, buffer[5 +p], unit->name,sizeof (unit->name)) <0 )sprintf (unit->name,"Selector %u" , buffer[3 ]);list_add_tail (&unit->list, &dev->entities);
@@ -1259,10 +1253,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev,if (dev->uvc_version >=0x0110 ) unit->processing.bmVideoStandards = buffer[9 +n]; -if (buffer[8 +n] !=0 ) -usb_string (udev, buffer[8 +n], unit->name, -sizeof (unit->name)); -else +if (buffer[8 +n] ==0 || +usb_string (udev, buffer[8 +n], unit->name,sizeof (unit->name)) <0 )sprintf (unit->name,"Processing %u" , buffer[3 ]);list_add_tail (&unit->list, &dev->entities);
@@ -1290,10 +1282,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev, unit->extension.bmControls = (u8 *)unit +sizeof (*unit);memcpy (unit->extension.bmControls, &buffer[23 +p], n); -if (buffer[23 +p+n] !=0 ) -usb_string (udev, buffer[23 +p+n], unit->name, -sizeof (unit->name)); -else +if (buffer[23 +p+n] ==0 || +usb_string (udev, buffer[23 +p+n], unit->name,sizeof (unit->name)) <0 )sprintf (unit->name,"Extension %u" , buffer[3 ]);list_add_tail (&unit->list, &dev->entities);
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 4/16 media: uvcvideo: Silence memcpy() run-time false positive warnings
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ Upstream commit b839212988575c701aab4d3d9ca15e44c87e383c ]
The memcpy() in uvc_video_decode_meta() intentionally copies across the length and flags members and into the trailing buf flexible array. Split the copy so that the compiler can better reason about (the lack of) buffer overflows here. Avoid the run-time false positive warning:
memcpy: detected field-spanning write (size 12) of single field "&meta->length" at drivers/media/usb/uvc/uvc_video.c:1355 (size 1)
Additionally fix a typo in the documentation for struct uvc_meta_buf.
--- drivers/media/usb/uvc/uvc_video.c | 4 +++- include/uapi/linux/uvcvideo.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +3 -1
@@ -1278,7 +1278,9 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,if (has_scr)memcpy (stream->clock.last_scr, scr,6 ); -memcpy (&meta->length, mem, length); + meta->length = mem[0 ]; + meta->flags = mem[1 ]; +memcpy (meta->buf, &mem[2 ], length -2 ); meta_buf->bytesused += length +sizeof (meta->ns) +sizeof (meta->sof); uvc_trace(UVC_TRACE_FRAME,
include/uapi/linux/uvcvideo.h +1 -1
@@ -86,7 +86,7 @@ struct uvc_xu_control_query {* struct. The first two fields are added by the driver, they can be used for * clock synchronisation. The rest is an exact copy of a UVC payload header. * Only complete objects with complete buffers are included. Therefore it's -* always sizeof(meta->ts) + sizeof(meta->sof) + meta->length bytes large. +* always sizeof(meta->ns) + sizeof(meta->sof) + meta->length bytes large. */ struct uvc_meta_buf {__u64 ns;
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 5/16 tty: fix out-of-bounds access in tty_driver_lookup_tty()
In reply to Sasha LevinFrom: Sven Schnelle <[email protected]>
[ Upstream commit db4df8e9d79e7d37732c1a1b560958e8dadfefa1 ]
When specifying an invalid console= device like console=tty3270, tty_driver_lookup_tty() returns the tty struct without checking whether index is a valid number.
To reproduce:
qemu-system-x86_64 -enable-kvm -nographic -serial mon:stdio \
-kernel ../linux-build-x86/arch/x86/boot/bzImage \
-append "console=ttyS0 console=tty3270"
This crashes with:
[ 0.770599] BUG: kernel NULL pointer dereference, address: 00000000000000ef [ 0.771265] #PF: supervisor read access in kernel mode [ 0.771773] #PF: error_code(0x0000) - not-present page [ 0.772609] Oops: 0000 [#1] PREEMPT SMP PTI [ 0.774878] RIP: 0010:tty_open+0x268/0x6f0 [ 0.784013] chrdev_open+0xbd/0x230 [ 0.784444] ? cdev_device_add+0x80/0x80 [ 0.784920] do_dentry_open+0x1e0/0x410 [ 0.785389] path_openat+0xca9/0x1050 [ 0.785813] do_filp_open+0xaa/0x150 [ 0.786240] file_open_name+0x133/0x1b0 [ 0.786746] filp_open+0x27/0x50 [ 0.787244] console_on_rootfs+0x14/0x4d [ 0.787800] kernel_init_freeable+0x1e4/0x20d [ 0.788383] ? rest_init+0xc0/0xc0 [ 0.788881] kernel_init+0x11/0x120 [ 0.789356] ret_from_fork+0x22/0x30
--- drivers/tty/tty_io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/tty/tty_io.c +5 -3
@@ -1155,14 +1155,16 @@ static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, {struct tty_struct *tty; -if (driver->ops->lookup) +if (driver->ops->lookup) {if (!file) tty =ERR_PTR (-EIO );else tty = driver->ops->lookup (driver, file, idx); -else + }else { +if (idx >= driver->num) +return ERR_PTR (-EINVAL ); tty = driver->ttys[idx]; - + }if (!IS_ERR (tty))tty_kref_get (tty);return tty;
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 6/16 tty: serial: fsl_lpuart: disable the CTS when send break signal
In reply to Sasha LevinFrom: Sherry Sun <[email protected]>
[ Upstream commit c4c81db5cf8bc53d6160c3abf26d382c841aa434 ]
LPUART IP has a bug that it treats the CTS as higher priority than the break signal, which cause the break signal sending through UARTCTRL_SBK may impacted by the CTS input if the HW flow control is enabled.
Add this workaround patch to fix the IP bug, we can disable CTS before asserting SBK to avoid any interference from CTS, and re-enable it when break off.
Such as for the bluetooth chip power save feature, host can let the BT chip get into sleep state by sending a UART break signal, and wake it up by turning off the UART break. If the BT chip enters the sleep mode successfully, it will pull up the CTS line, if the BT chip is woken up, it will pull down the CTS line. If without this workaround patch, the UART TX pin cannot send the break signal successfully as it affected by the BT CTS pin. After adding this patch, the BT power save feature can work well.
--- drivers/tty/serial/fsl_lpuart.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +22 -2
@@ -1195,12 +1195,32 @@ static void lpuart_break_ctl(struct uart_port *port, int break_state)static void lpuart32_break_ctl (struct uart_port *port,int break_state) { -unsigned long temp; +unsigned long temp, modem; +struct tty_struct *tty; +unsigned int cflag =0 ; + + tty =tty_port_tty_get (&port->state->port); +if (tty) { + cflag = tty->termios.c_cflag; +tty_kref_put (tty); + } temp =lpuart32_read (port,UARTCTRL ) & ~UARTCTRL_SBK ; + modem =lpuart32_read (port,UARTMODIR ); -if (break_state !=0 ) +if (break_state !=0 ) { temp |=UARTCTRL_SBK ; +/* +* LPUART CTS has higher priority than SBK, need to disable CTS before +* asserting SBK to avoid any interference if flow control is enabled. +*/ +if (cflag &CRTSCTS && modem &UARTMODIR_TXCTSE ) +lpuart32_write (port, modem & ~UARTMODIR_TXCTSE ,UARTMODIR ); + }else { +/* Re-enable the CTS when break off. */ +if (cflag &CRTSCTS && !(modem &UARTMODIR_TXCTSE )) +lpuart32_write (port, modem |UARTMODIR_TXCTSE ,UARTMODIR ); + }lpuart32_write (port, temp,UARTCTRL ); }
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 7/16 mei: bus-fixup:upon error print return values of send and receive
In reply to Sasha LevinFrom: Alexander Usyskin <[email protected]>
[ Upstream commit 4b8659e2c258e4fdac9ccdf06cc20c0677894ef9 ]
For easier debugging, upon error, print also return values from __mei_cl_recv() and __mei_cl_send() functions.
--- drivers/misc/mei/bus-fixup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/misc/mei/bus-fixup.c +4 -4
@@ -174,7 +174,7 @@ static int mei_fwver(struct mei_cl_device *cldev) ret =__mei_cl_send (cldev->cl, buf,sizeof (struct mkhi_msg_hdr ),MEI_CL_IO_TX_BLOCKING );if (ret <0 ) { -dev_err (&cldev->dev,"Could not send ReqFWVersion cmd\n" ); +dev_err (&cldev->dev,"Could not send ReqFWVersion cmd ret = %d\n" , ret);return ret; }
@@ -186,7 +186,7 @@ static int mei_fwver(struct mei_cl_device *cldev)* Should be at least one version block, * error out if nothing found */ -dev_err (&cldev->dev,"Could not read FW version\n" ); +dev_err (&cldev->dev,"Could not read FW version ret = %d\n" , bytes_recv);return -EIO ; }
@@ -335,7 +335,7 @@ static int mei_nfc_if_version(struct mei_cl *cl, ret =__mei_cl_send (cl, (u8 *)&cmd,sizeof (struct mei_nfc_cmd ),MEI_CL_IO_TX_BLOCKING );if (ret <0 ) { -dev_err (bus->dev,"Could not send IF version cmd\n" ); +dev_err (bus->dev,"Could not send IF version cmd ret = %d\n" , ret);return ret; }
@@ -350,7 +350,7 @@ static int mei_nfc_if_version(struct mei_cl *cl, ret =0 ; bytes_recv =__mei_cl_recv (cl, (u8 *)reply, if_version_length,0 ,0 );if (bytes_recv <0 || (size_t )bytes_recv < if_version_length) { -dev_err (bus->dev,"Could not read IF version\n" ); +dev_err (bus->dev,"Could not read IF version ret = %d\n" , bytes_recv); ret = -EIO ; goto err; }
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 8/16 parport_pc: Set up mode and ECR masks for Oxford Semiconductor devices
In reply to Sasha LevinFrom: "Maciej W. Rozycki" <[email protected]>
[ Upstream commit c087df8d1e7dc2e764d11234d84b5af46d500f16 ]
No Oxford Semiconductor PCI or PCIe parallel port device supports the Parallel Port FIFO mode. All support the PS/2 Parallel Port mode and the Enhanced Parallel Port mode via the ECR register. The original 5V PCI OX16PCI954 device does not support the Extended Capabilities Port mode, the Test mode or the Configuration mode, but all the other OxSemi devices do, including in particular the 3.3V PCI OXmPCI954 device and the universal voltage PCI OXuPCI954 device. All the unsupported modes are marked reserved in the relevant datasheets.
Accordingly enable the `base_hi' BAR for the 954 devices to enable PS2 and EPP mode support via the ECR register, however mask the COMPAT mode and, until we have a way to determine what chip variant it is that we poke at, also the ECP mode, and mask the COMPAT mode only for all the remaining OxSemi devices, fixing errors like:
parport0: FIFO is stuck
FIFO write timed out
and a non-functional port when the Parallel Port FIFO mode is selected.
Complementing the fix apply an ECR mask for all these devices, which are documented to only permit writing to the mode field of the ECR register with a bit pattern of 00001 required to be written to bits 4:0 on mode field writes. No nFault or service interrupts are implemented, which will therefore never have to be enabled, though bit 2 does report the FIFO threshold status to be polled for in the ECP mode where supported.
We have a documented case of writing 1 to bit 2 causing a lock-up with at least one OX12PCI840 device (from old drivers/parport/ChangeLog):
2001-10-10 Tim Waugh <[email protected]>
* parport_pc.c: Support for OX12PCI840 PCI card (reported by [email protected]). Lock-ups diagnosed by Ronnie Arosa (and now we just don't trust its ECR).
which commit adbd321a17cc ("parport_pc: add base_hi BAR for oxsemi_840") must have broken and by applying an ECR mask here we prevent the lock-up from triggering. This could have been the reason for requiring 00001 to be written to bits 4:0 of ECR.
Update the inline comment accordingly; it has come from Linux 2.4.12 back in 2001 and predates the introduction of OXmPCI954 and OXuPCI954 devices that do support ECP.
References:
[1] "OX16PCI954 Integrated Quad UART and PCI interface", Oxford Semiconductor Ltd., Data Sheet Revision 1.3, Feb. 1999, Chapter 9 "Bidirectional Parallel Port", pp. 53-55
[2] "OX16PCI952 Data Sheet, Integrated High Performance Dual UARTs,
Parallel Port and 5.0v PCI interface", Oxford Semiconductor Ltd.,
DS_B008A_00, Datasheet rev 1.1, June 2001, Chapter 8 "Bi-directional
Parallel Port", pp. 52-56[3] "OXmPCI954 DATA SHEET Integrated High Performance Quad UARTs, 8-bit Local Bus/Parallel Port. 3.3v PCI/miniPCI interface.", Oxford Semiconductor Ltd., DS-0019, June 2005, Chapter 10 "Bidirectional Parallel Port", pp. 86-90
[4] "OXmPCI952 Data Sheet, Integrated High Performance Dual UARTs, 8-bit Local Bus/Parallel Port. 3.3v PCI/miniPCI interface.", Oxford Semiconductor Ltd., DS-0020, June 2005, Chapter 8 "Bidirectional Parallel Port", pp. 73-77
[5] "OX12PCI840 Integrated Parallel Port and PCI interface", Oxford Semiconductor Ltd., DS-0021, Jun 2005, Chapter 5 "Bi-directional Parallel Port", pp. 18-21
[6] "OXPCIe952 PCI Express Bridge to Dual Serial & Parallel Port", Oxford Semiconductor, Inc., DS-0046, Mar 06 08, Chapter "Parallel Port Function", pp. 59-62
[7] "OXPCIe840 PCI Express Bridge to Parallel Port", Oxford Semiconductor, Inc., DS-0049, Mar 06 08, Chapter "Parallel Port Function", pp. 15-18
[8] "OXuPCI954 Data Sheet, Integrated High Performance Quad UARTs, 8-bit Local Bus/Parallel Port, 3.3 V and 5 V (Universal Voltage) PCI Interface.", Oxford Semiconductor, Inc., DS-0058, 26 Jan 2009, Chapter 8 "Bidirectional Parallel Port", pp. 62-65
[9] "OXuPCI952 Data Sheet, Integrated High Performance Dual UARTs, 8-bit Local Bus/Parallel Port, 3.3 V and 5.0 V Universal Voltage PCI Interface.", Oxford Semiconductor, Inc., DS-0059, Sep 2007, Chapter 8 "Bidirectional Parallel Port", pp. 61-64
--- drivers/parport/parport_pc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/parport/parport_pc.c +13 -6
@@ -2691,12 +2691,19 @@ static struct parport_pc_pci { /* titan_010l */ { 1, { { 3, -1 }, } }, /* avlab_1p */ { 1, { { 0, 1}, } }, /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} }, - /* The Oxford Semi cards are unusual: 954 doesn't support ECP, - * and 840 locks up if you write 1 to bit 2! */ - /* oxsemi_952 */ { 1, { { 0, 1 }, } }, - /* oxsemi_954 */ { 1, { { 0, -1 }, } }, - /* oxsemi_840 */ { 1, { { 0, 1 }, } }, - /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, + /* The Oxford Semi cards are unusual: older variants of 954 don't + * support ECP, and 840 locks up if you write 1 to bit 2! None + * implement nFault or service interrupts and all require 00001 + * bit pattern to be used for bits 4:0 with ECR writes. */ + /* oxsemi_952 */ { 1, { { 0, 1 }, }, + PARPORT_MODE_COMPAT, ECR_MODE_MASK }, + /* oxsemi_954 */ { 1, { { 0, 1 }, }, + PARPORT_MODE_ECP | + PARPORT_MODE_COMPAT, ECR_MODE_MASK }, + /* oxsemi_840 */ { 1, { { 0, 1 }, }, + PARPORT_MODE_COMPAT, ECR_MODE_MASK }, + /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, }, + PARPORT_MODE_COMPAT, ECR_MODE_MASK }, /* aks_0100 */ { 1, { { 0, -1 }, } }, /* mobility_pp */ { 1, { { 0, 1 }, } },
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 9/16 tools/iio/iio_utils:fix memory leak
In reply to Sasha LevinFrom: Yulong Zhang <[email protected]>
[ Upstream commit f2edf0c819a4823cd6c288801ce737e8d4fcde06 ]
1. fopen sysfs without fclose.
2. asprintf filename without free.
3. if asprintf return error,do not need to free the buffer.
--- tools/iio/iio_utils.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
tools/iio/iio_utils.c +6 -17
@@ -265,6 +265,7 @@ int iioutils_get_param_float(float *output, const char *param_name,if (fscanf (sysfsfp,"%f" , output) !=1 ) ret = errno ? -errno : -ENODATA ; +fclose (sysfsfp);break ; } error_free_filename:
@@ -345,9 +346,9 @@ int build_channel_array(const char *device_dir, } sysfsfp =fopen (filename,"r" ); +free (filename);if (!sysfsfp) { ret = -errno; -free (filename); goto error_close_dir; }
@@ -357,7 +358,6 @@ int build_channel_array(const char *device_dir,if (fclose (sysfsfp))perror ("build_channel_array(): Failed to close file" ); -free (filename); goto error_close_dir; }if (ret ==1 )
@@ -365,11 +365,9 @@ int build_channel_array(const char *device_dir,if (fclose (sysfsfp)) { ret = -errno; -free (filename); goto error_close_dir; } -free (filename); } *ci_array =malloc (sizeof (**ci_array) * (*counter));
@@ -395,9 +393,9 @@ int build_channel_array(const char *device_dir, } sysfsfp =fopen (filename,"r" ); +free (filename);if (!sysfsfp) { ret = -errno; -free (filename); count--; goto error_cleanup_array; }
@@ -405,20 +403,17 @@ int build_channel_array(const char *device_dir, errno =0 ;if (fscanf (sysfsfp,"%i" , ¤t_enabled) !=1 ) { ret = errno ? -errno : -ENODATA ; -free (filename); count--; goto error_cleanup_array; }if (fclose (sysfsfp)) { ret = -errno; -free (filename); count--; goto error_cleanup_array; }if (!current_enabled) { -free (filename); count--;continue ; }
@@ -429,7 +424,6 @@ int build_channel_array(const char *device_dir,strlen (ent->d_name) - strlen("_en"));if (!current->name) { -free (filename); ret = -ENOMEM ; count--; goto error_cleanup_array;
@@ -439,7 +433,6 @@ int build_channel_array(const char *device_dir, ret =iioutils_break_up_name (current->name, ¤t->generic_name);if (ret) { -free (filename);free (current->name); count--; goto error_cleanup_array;
@@ -450,17 +443,16 @@ int build_channel_array(const char *device_dir, scan_el_dir, current->name);if (ret <0 ) { -free (filename); ret = -ENOMEM ; goto error_cleanup_array; } sysfsfp =fopen (filename,"r" ); +free (filename);if (!sysfsfp) { ret = -errno; -fprintf (stderr,"failed to open %s\n" , - filename); -free (filename); +fprintf (stderr,"failed to open %s/%s_index\n" , + scan_el_dir, current->name); goto error_cleanup_array; }
@@ -470,17 +462,14 @@ int build_channel_array(const char *device_dir,if (fclose (sysfsfp))perror ("build_channel_array(): Failed to close file" ); -free (filename); goto error_cleanup_array; }if (fclose (sysfsfp)) { ret = -errno; -free (filename); goto error_cleanup_array; } -free (filename);/* Find the scale */ ret = iioutils_get_param_float(¤t->scale, "scale",
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 10/16 iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_status_word()
In reply to Sasha LevinFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit e56d2c34ce9dc122b1a618172ec0e05e50adb9e9 ]
Smatch Warns: drivers/iio/accel/mma9551_core.c:357
mma9551_read_status_word() error: uninitialized symbol 'v'.
When (offset >= 1 << 12) is true mma9551_transfer() will return -EINVAL without 'v' being initialized, so check for the error and return.
Note: Not a bug as such because the caller checks return value and doesn't not use this parameter in the problem case.
--- drivers/iio/accel/mma9551_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/accel/mma9551_core.c +4 -1
@@ -362,9 +362,12 @@ int mma9551_read_status_word(struct i2c_client *client, u8 app_id, ret =mma9551_transfer (client, app_id,MMA9551_CMD_READ_STATUS , reg,NULL ,0 , (u8 *)&v,2 ); +if (ret <0 ) +return ret; + *val =be16_to_cpu (v); -return ret; +return 0 ; }EXPORT_SYMBOL (mma9551_read_status_word);
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 11/16 iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word()
In reply to Sasha LevinFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit 64a68158738ec8f520347144352f7a09bdb9e169 ]
Smatch Warns:drivers/iio/accel/mma9551_core.c:299
mma9551_read_config_word() error: uninitialized symbol 'v'.
When (offset >= 1 << 12) is true mma9551_transfer() will return -EINVAL without 'v' being initialized, so check for the error and return.
Note: No actual bug as caller checks the return value and does not use the parameter in the problem case.
--- drivers/iio/accel/mma9551_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/accel/mma9551_core.c +4 -1
@@ -304,9 +304,12 @@ int mma9551_read_config_word(struct i2c_client *client, u8 app_id, ret =mma9551_transfer (client, app_id,MMA9551_CMD_READ_CONFIG , reg,NULL ,0 , (u8 *)&v,2 ); +if (ret <0 ) +return ret; + *val =be16_to_cpu (v); -return ret; +return 0 ; }EXPORT_SYMBOL (mma9551_read_config_word);
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 12/16 firmware: coreboot: framebuffer: Ignore reserved pixel color bits
In reply to Sasha LevinFrom: Alper Nebi Yasak <[email protected]>
[ Upstream commit e6acaf25cba14661211bb72181c35dd13b24f5b3 ]
The coreboot framebuffer doesn't support transparency, its 'reserved' bit field is merely padding for byte/word alignment of pixel colors [1]. When trying to match the framebuffer to a simplefb format, the kernel driver unnecessarily requires the format's transparency bit field to exactly match this padding, even if the former is zero-width.
Due to a coreboot bug [2] (fixed upstream), some boards misreport the reserved field's size as equal to its position (0x18 for both on a 'Lick' Chromebook), and the driver fails to probe where it would have otherwise worked fine with e.g. the a8r8g8b8 or x8r8g8b8 formats.
Remove the transparency comparison with reserved bits. When the bits-per-pixel and other color components match, transparency will already be in a subset of the reserved field. Not forcing it to match reserved bits allows the driver to work on the boards which misreport the reserved field. It also enables using simplefb formats that don't have transparency bits, although this doesn't currently happen due to format support and ordering in linux/platform_data/simplefb.h.
[1] https://review.coreboot.org/plugins/gitiles/coreboot/+/4.19/src/commonlib/include/commonlib/coreboot_tables.h#255
[2] https://review.coreboot.org/plugins/gitiles/coreboot/+/4.13/src/drivers/intel/fsp2_0/graphics.c#82
--- drivers/firmware/google/framebuffer-coreboot.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/firmware/google/framebuffer-coreboot.c +1 -3
@@ -51,9 +51,7 @@ static int framebuffer_probe(struct coreboot_device *dev) fb->green_mask_pos == formats[i].green.offset && fb->green_mask_size == formats[i].green.length && fb->blue_mask_pos == formats[i].blue.offset && - fb->blue_mask_size == formats[i].blue.length && - fb->reserved_mask_pos == formats[i].transp.offset && - fb->reserved_mask_size == formats[i].transp.length) + fb->blue_mask_size == formats[i].blue.length) pdata.format = formats[i].name; }if (!pdata.format)
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 13/16 usb: host: xhci: mvebu: Iterate over array indexes instead of using pointer math
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ Upstream commit 0fbd2cda92cdb00f72080665554a586f88bca821 ]
Walking the dram->cs array was seen as accesses beyond the first array item by the compiler. Instead, use the array index directly. This allows for run-time bounds checking under CONFIG_UBSAN_BOUNDS as well. Seen with GCC 13 with -fstrict-flex-arrays:
In function 'xhci_mvebu_mbus_config',
inlined from 'xhci_mvebu_mbus_init_quirk' at ../drivers/usb/host/xhci-mvebu.c:66:2:../drivers/usb/host/xhci-mvebu.c:37:28: warning: array subscript 0 is outside array bounds of 'const struct mbus_dram_window[0]' [-Warray-bounds=]
37 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
| ~~^~~~~~
--- drivers/usb/host/xhci-mvebu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-mvebu.c +1 -1
@@ -31,7 +31,7 @@ static void xhci_mvebu_mbus_config(void __iomem *base,/* Program each DRAM CS in a seperate window */ for (win =0 ; win < dram->num_cs; win++) { -const struct mbus_dram_window *cs = dram->cs + win; +const struct mbus_dram_window *cs = &dram->cs[win]; writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | (dram->mbus_dram_target_id << 4) | 1,
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 14/16 USB: ene_usb6250: Allocate enough memory for full object
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ Upstream commit ce33e64c1788912976b61314b56935abd4bc97ef ]
The allocation of PageBuffer is 512 bytes in size, but the dereferencing of struct ms_bootblock_idi (also size 512) happens at a calculated offset within the allocation, which means the object could potentially extend beyond the end of the allocation. Avoid this case by just allocating enough space to catch any accesses beyond the end. Seen with GCC 13:
../drivers/usb/storage/ene_ub6250.c: In function 'ms_lib_process_bootblock':../drivers/usb/storage/ene_ub6250.c:1050:44: warning: array subscript 'struct ms_bootblock_idi[0]' is partly outside array bounds of 'unsigned char[512]' [-Warray-bounds=]
1050 | if (le16_to_cpu(idi->wIDIgeneralConfiguration) != MS_IDI_GENERAL_CONF)
| ^~../include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^../drivers/usb/storage/ene_ub6250.c:1050:29: note: in expansion of macro 'le16_to_cpu'
1050 | if (le16_to_cpu(idi->wIDIgeneralConfiguration) != MS_IDI_GENERAL_CONF)
| ^~~~~~~~~~~
In file included from ../drivers/usb/storage/ene_ub6250.c:5:
In function 'kmalloc',
inlined from 'ms_lib_process_bootblock' at ../drivers/usb/storage/ene_ub6250.c:942:15:
../include/linux/slab.h:580:24: note: at offset [256, 512] into object of size 512 allocated by 'kmalloc_trace'
580 | return kmalloc_trace(
| ^~~~~~~~~~~~~~
581 | kmalloc_caches[kmalloc_type(flags)][index],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
582 | flags, size);
| ~~~~~~~~~~~~--- drivers/usb/storage/ene_ub6250.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/storage/ene_ub6250.c +1 -1
@@ -937,7 +937,7 @@ static int ms_lib_process_bootblock(struct us_data *us, u16 PhyBlock, u8 *PageDastruct ms_lib_type_extdat ExtraData;struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; - PageBuffer =kmalloc (MS_BYTES_PER_PAGE ,GFP_KERNEL ); + PageBuffer =kzalloc (MS_BYTES_PER_PAGE *2 ,GFP_KERNEL );if (PageBuffer ==NULL )return (u32)-1 ;
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 15/16 usb: uvc: Enumerate valid values for color matching
In reply to Sasha LevinFrom: Daniel Scally <[email protected]>
[ Upstream commit e16cab9c1596e251761d2bfb5e1467950d616963 ]
The color matching descriptors defined in the UVC Specification contain 3 fields with discrete numeric values representing particular settings. Enumerate those values so that later code setting them can be more readable.
--- include/uapi/linux/usb/video.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
include/uapi/linux/usb/video.h +30 -0
@@ -179,6 +179,36 @@#define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3)#define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4) +/* 3.9.2.6 Color Matching Descriptor Values */ +enum uvc_color_primaries_values { +UVC_COLOR_PRIMARIES_UNSPECIFIED , +UVC_COLOR_PRIMARIES_BT_709_SRGB , +UVC_COLOR_PRIMARIES_BT_470_2_M , +UVC_COLOR_PRIMARIES_BT_470_2_B_G , +UVC_COLOR_PRIMARIES_SMPTE_170M , +UVC_COLOR_PRIMARIES_SMPTE_240M , +}; + +enum uvc_transfer_characteristics_values { +UVC_TRANSFER_CHARACTERISTICS_UNSPECIFIED , +UVC_TRANSFER_CHARACTERISTICS_BT_709 , +UVC_TRANSFER_CHARACTERISTICS_BT_470_2_M , +UVC_TRANSFER_CHARACTERISTICS_BT_470_2_B_G , +UVC_TRANSFER_CHARACTERISTICS_SMPTE_170M , +UVC_TRANSFER_CHARACTERISTICS_SMPTE_240M , +UVC_TRANSFER_CHARACTERISTICS_LINEAR , +UVC_TRANSFER_CHARACTERISTICS_SRGB , +}; + +enum uvc_matrix_coefficients { +UVC_MATRIX_COEFFICIENTS_UNSPECIFIED , +UVC_MATRIX_COEFFICIENTS_BT_709 , +UVC_MATRIX_COEFFICIENTS_FCC , +UVC_MATRIX_COEFFICIENTS_BT_470_2_B_G , +UVC_MATRIX_COEFFICIENTS_SMPTE_170M , +UVC_MATRIX_COEFFICIENTS_SMPTE_240M , +}; +/* ------------------------------------------------------------------------ * UVC structures */
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 16/16 phy: rockchip-typec: Fix unsigned comparison with less than zero
In reply to Sasha LevinFrom: Jiapeng Chong <[email protected]>
[ Upstream commit f765c59c5a72546a2d74a92ae5d0eb0329d8e247 ]
The dp and ufp are defined as bool type, the return value type of function extcon_get_state should be int, so the type of dp and ufp are modified to int.
./drivers/phy/rockchip/phy-rockchip-typec.c:827:12-14: WARNING: Unsigned expression compared with zero: dp > 0.
--- drivers/phy/rockchip/phy-rockchip-typec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/phy/rockchip/phy-rockchip-typec.c +1 -2
@@ -817,9 +817,8 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)struct extcon_dev *edev = tcphy->extcon;union extcon_property_value property;unsigned int id; -bool ufp, dp;u8 mode; -int ret; +int ret, ufp, dp;if (!edev)return MODE_DFP_USB ;
Signature · 7 lines
2.39.2 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy