lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8a2467b9-4eb5-4ab4-a4c8-da37875fe4c9@kernel.org>
Date: Mon, 8 Jul 2024 10:04:41 +0200
From: Johannes Thumshirn <jth@...nel.org>
To: Mark Brown <broonie@...nel.org>
Cc: linux-kernel@...r.kernel.org, linux-spi@...r.kernel.org
Subject: Re: [PATCH] spi: add ch341a usb2spi driver

On 05/07/2024 19:41, Mark Brown wrote:
>> +config SPI_CH341
>> +	tristate "CH341 USB2SPI adapter"
>> +	depends on SPI_MASTER && USB
>> +	help
>> +	  Enables the SPI controller on the CH341a USB to serial chip
>> +
>>   #
>>   # Add new SPI master controllers in alphabetical order above this line
>>   #
> 
> Like the comment says please keep these files sorted (I appreciate
> there's some things been missed).

Oops. Fixed, sorry.

> 
>> +++ b/drivers/spi/spi-ch341.c
>> @@ -0,0 +1,236 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * QiHeng Electronics ch341a USB-to-SPI adapter driver
>> + *
>> + * Copyright (C) 2024 Johannes Thumshirn <jth@...nel.org>
> 
> Please make the entire comment block a C++ one so things look clearer.

I've never seen that in kernel code, but sure changed it.

> 
>> +static void ch341_set_cs(struct spi_device *spi, bool is_high)
>> +{
>> +	struct ch341_spi_dev *ch341 =
>> +		spi_controller_get_devdata(spi->controller);
>> +
>> +	memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH);
>> +	ch341->tx_buf[0] = CH341A_CMD_UIO_STREAM;
>> +	ch341->tx_buf[1] = CH341A_CMD_UIO_STM_OUT | (is_high ? 0x36 : 0x37);
>> +
>> +	if (is_high) {
>> +		ch341->tx_buf[2] = CH341A_CMD_UIO_STM_DIR | 0x3f;
>> +		ch341->tx_buf[3] = CH341A_CMD_UIO_STM_END;
>> +	} else {
>> +		ch341->tx_buf[2] = CH341A_CMD_UIO_STM_END;
>> +	}
>> +
>> +	(void)usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf,
>> +			   (is_high ? 4 : 3), NULL, CH341_DEFAULT_TIMEOUT);
> 
> The cast to void here is very suspicious, what's it doing?

Explicitly ignoring errors from usb_bulk_msg() as ->set_cs() can't 
really handle error returns.

I've changed it to an error print.


> 
>> +static int ch341_config_stream(struct ch341_spi_dev *ch341, int speed)
>> +{
>> +	memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH);
>> +	ch341->tx_buf[0] = CH341A_CMD_I2C_STREAM;
>> +	ch341->tx_buf[1] = CH341A_CMD_I2C_STM_SET | (speed & 0x7);
>> +	ch341->tx_buf[2] = CH341A_CMD_I2C_STM_END;
>> +
>> +	return usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, 3,
>> +			    NULL, CH341_DEFAULT_TIMEOUT);
> 
> No validation of speed?

TBH I haven't found a command that reads the current settings of the device.


Download attachment "OpenPGP_0x0393969D2D760850.asc" of type "application/pgp-keys" (23375 bytes)

Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (237 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ