From f7c04f16d76e795f52a8fdbf11d351346fe7032c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 11 Sep 2017 11:00:13 +0200 Subject: nvmem: remove inline in drivers/nvmem/core.c These two functions are defined in .c file, but called just once (at least for now). So, the compiler will fold them into their callers even without the "inline" markers. However, this kind of optimization should not be done by hand. It is compiler's judge after all. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index de54c7f5048a..730cc06656c8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -945,8 +945,7 @@ void nvmem_cell_put(struct nvmem_cell *cell) } EXPORT_SYMBOL_GPL(nvmem_cell_put); -static inline void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, - void *buf) +static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf) { u8 *p, *b; int i, bit_offset = cell->bit_offset; @@ -1027,8 +1026,8 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) } EXPORT_SYMBOL_GPL(nvmem_cell_read); -static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, - u8 *_buf, int len) +static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, + u8 *_buf, int len) { struct nvmem_device *nvmem = cell->nvmem; int i, rc, nbits, bit_offset = cell->bit_offset; -- cgit v1.2.3-58-ga151 From e701c67c30e65cc887b1ebdd6ef91010f0ca46fa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 11 Sep 2017 11:00:14 +0200 Subject: nvmem: remove unneeded IS_ENABLED(CONFIG_NVMEM) conditional As you see in drivers/nvmem/Makefile, this C file is compiled only when CONFIG_NVMEM is y or m. So, IS_ENABLED(CONFIG_NVMEM) is always evaluated to 1 in this file. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 730cc06656c8..0a3464f647a4 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -615,7 +615,7 @@ static struct nvmem_device *nvmem_find(const char *name) return to_nvmem_device(d); } -#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) +#if IS_ENABLED(CONFIG_OF) /** * of_nvmem_device_get() - Get nvmem device from a given id * @@ -753,7 +753,7 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id) return cell; } -#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) +#if IS_ENABLED(CONFIG_OF) /** * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id * -- cgit v1.2.3-58-ga151 From eb8470db8bc018fc28901e4e3b0f48e33f1ea7df Mon Sep 17 00:00:00 2001 From: Jan Kandziora Date: Wed, 20 Sep 2017 23:52:45 +0200 Subject: wire: export w1_touch_bit The w1_ds28e17 driver from the next part of this patch needs to emit single-bit read timeslots to the DS28E17. The w1 subsystem already has this function but it is not exported outside drivers/w1/w1_io.c This subpatch exports the w1_touch_bit symbol with EXPORT_SYMBOL_GPL, same as the other exported symbols in drivers/w1/w1_io.c May be also useful later for writing drivers for other Onewire chips which do single-bit communication. Signed-off-by: Jan Kandziora Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_io.c | 3 ++- include/linux/w1.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index d191e1f80579..075d120e7b88 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c @@ -58,7 +58,7 @@ static u8 w1_read_bit(struct w1_master *dev); * @dev: the master device * @bit: 0 - write a 0, 1 - write a 0 read the level */ -static u8 w1_touch_bit(struct w1_master *dev, int bit) +u8 w1_touch_bit(struct w1_master *dev, int bit) { if (dev->bus_master->touch_bit) return dev->bus_master->touch_bit(dev->bus_master->data, bit); @@ -69,6 +69,7 @@ static u8 w1_touch_bit(struct w1_master *dev, int bit) return 0; } } +EXPORT_SYMBOL_GPL(w1_touch_bit); /** * w1_write_bit() - Generates a write-0 or write-1 cycle. diff --git a/include/linux/w1.h b/include/linux/w1.h index 5b2972946dda..694101f744c7 100644 --- a/include/linux/w1.h +++ b/include/linux/w1.h @@ -293,6 +293,7 @@ void w1_unregister_family(struct w1_family *family); w1_unregister_family) u8 w1_triplet(struct w1_master *dev, int bdir); +u8 w1_touch_bit(struct w1_master *dev, int bit); void w1_write_8(struct w1_master *, u8); u8 w1_read_8(struct w1_master *); int w1_reset_bus(struct w1_master *); -- cgit v1.2.3-58-ga151 From ebc4768ac4971eab4b570e733e47ac9dfd0e4175 Mon Sep 17 00:00:00 2001 From: Jan Kandziora Date: Wed, 20 Sep 2017 23:52:46 +0200 Subject: add w1_ds28e17 driver for the DS28E17 Onewire to I2C master bridge This subpatch adds a driver for the DS28E17 Onewire to I2C master bridge. Signed-off-by: Jan Kandziora Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-driver-w1_ds28e17 | 21 + Documentation/w1/slaves/00-INDEX | 2 + Documentation/w1/slaves/w1_ds28e17 | 68 ++ drivers/w1/slaves/Kconfig | 15 + drivers/w1/slaves/Makefile | 1 + drivers/w1/slaves/w1_ds28e17.c | 771 ++++++++++++++++++++++ 6 files changed, 878 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-w1_ds28e17 create mode 100644 Documentation/w1/slaves/w1_ds28e17 create mode 100644 drivers/w1/slaves/w1_ds28e17.c (limited to 'drivers') diff --git a/Documentation/ABI/testing/sysfs-driver-w1_ds28e17 b/Documentation/ABI/testing/sysfs-driver-w1_ds28e17 new file mode 100644 index 000000000000..d301e7017afe --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-w1_ds28e17 @@ -0,0 +1,21 @@ +What: /sys/bus/w1/devices/19-/speed +Date: Sep 2017 +KernelVersion: 4.14 +Contact: Jan Kandziora +Description: When written, this file sets the I2C speed on the connected + DS28E17 chip. When read, it reads the current setting from + the DS28E17 chip. + Valid values: 100, 400, 900 [kBaud]. + Default 100, can be set by w1_ds28e17.speed= module parameter. +Users: w1_ds28e17 driver + +What: /sys/bus/w1/devices/19-/stretch +Date: Sep 2017 +KernelVersion: 4.14 +Contact: Jan Kandziora +Description: When written, this file sets the multiplier used to calculate + the busy timeout for I2C operations on the connected DS28E17 + chip. When read, returns the current setting. + Valid values: 1 to 9. + Default 1, can be set by w1_ds28e17.stretch= module parameter. +Users: w1_ds28e17 driver diff --git a/Documentation/w1/slaves/00-INDEX b/Documentation/w1/slaves/00-INDEX index 8d76718e1ea2..68946f83e579 100644 --- a/Documentation/w1/slaves/00-INDEX +++ b/Documentation/w1/slaves/00-INDEX @@ -10,3 +10,5 @@ w1_ds2438 - The Maxim/Dallas Semiconductor ds2438 smart battery monitor. w1_ds28e04 - The Maxim/Dallas Semiconductor ds28e04 eeprom. +w1_ds28e17 + - The Maxim/Dallas Semiconductor ds28e17 1-Wire-to-I2C Master Bridge. diff --git a/Documentation/w1/slaves/w1_ds28e17 b/Documentation/w1/slaves/w1_ds28e17 new file mode 100644 index 000000000000..7fcfad5b4a37 --- /dev/null +++ b/Documentation/w1/slaves/w1_ds28e17 @@ -0,0 +1,68 @@ +Kernel driver w1_ds28e17 +======================== + +Supported chips: + * Maxim DS28E17 1-Wire-to-I2C Master Bridge + +supported family codes: + W1_FAMILY_DS28E17 0x19 + +Author: Jan Kandziora + + +Description +----------- +The DS28E17 is a Onewire slave device which acts as an I2C bus master. + +This driver creates a new I2C bus for any DS28E17 device detected. I2C buses +come and go as the DS28E17 devices come and go. I2C slave devices connected to +a DS28E17 can be accessed by the kernel or userspace tools as if they were +connected to a "native" I2C bus master. + + +An udev rule like the following +------------------------------------------------------------------------------- +SUBSYSTEM=="i2c-dev", KERNEL=="i2c-[0-9]*", ATTRS{name}=="w1-19-*", \ + SYMLINK+="i2c-$attr{name}" +------------------------------------------------------------------------------- +may be used to create stable /dev/i2c- entries based on the unique id of the +DS28E17 chip. + + +Driver parameters are: + +speed: + This sets up the default I2C speed a DS28E17 get configured for as soon + it is connected. The power-on default of the DS28E17 is 400kBaud, but + chips may come and go on the Onewire bus without being de-powered and + as soon the "w1_ds28e17" driver notices a freshly connected, or + reconnected DS28E17 device on the Onewire bus, it will re-apply this + setting. + + Valid values are 100, 400, 900 [kBaud]. Any other value means to leave + alone the current DS28E17 setting on detect. The default value is 100. + +stretch: + This sets up the default stretch value used for freshly connected + DS28E17 devices. It is a multiplier used on the calculation of the busy + wait time for an I2C transfer. This is to account for I2C slave devices + which make heavy use of the I2C clock stretching feature and thus, the + needed timeout cannot be pre-calculated correctly. As the w1_ds28e17 + driver checks the DS28E17's busy flag in a loop after the precalculated + wait time, it should be hardly needed to tweak this setting. + + Leave it at 1 unless you get ETIMEDOUT errors and a "w1_slave_driver + 19-00000002dbd8: busy timeout" in the kernel log. + + Valid values are 1 to 9. The default is 1. + + +The driver creates sysfs files /sys/bus/w1/devices/19-/speed and +/sys/bus/w1/devices/19-/stretch for each device, preloaded with the default +settings from the driver parameters. They may be changed anytime. In addition a +directory /sys/bus/w1/devices/19-/i2c- for the I2C bus master sysfs +structure is created. + + +See https://github.com/ianka/w1_ds28e17 for even more information. + diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig index 3c945f9f5f0f..7931231d8e80 100644 --- a/drivers/w1/slaves/Kconfig +++ b/drivers/w1/slaves/Kconfig @@ -148,4 +148,19 @@ config W1_SLAVE_DS28E04 If you are unsure, say N. +config W1_SLAVE_DS28E17 + tristate "1-wire-to-I2C master bridge (DS28E17)" + select CRC16 + depends on I2C + help + Say Y here if you want to use the DS28E17 1-wire-to-I2C master bridge. + For each DS28E17 detected, a new I2C adapter is created within the + kernel. I2C devices on that bus can be configured to be used by the + kernel and userspace tools as on any other "native" I2C bus. + + This driver is also available as a module. If so, the module + will be called w1_ds28e17. + + If you are unsure, say N. + endmenu diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile index 36b22fb2d3a1..855371a99e6a 100644 --- a/drivers/w1/slaves/Makefile +++ b/drivers/w1/slaves/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o obj-$(CONFIG_W1_SLAVE_DS28E04) += w1_ds28e04.o +obj-$(CONFIG_W1_SLAVE_DS28E17) += w1_ds28e17.o diff --git a/drivers/w1/slaves/w1_ds28e17.c b/drivers/w1/slaves/w1_ds28e17.c new file mode 100644 index 000000000000..e78b63ea4daf --- /dev/null +++ b/drivers/w1/slaves/w1_ds28e17.c @@ -0,0 +1,771 @@ +/* + * w1_ds28e17.c - w1 family 19 (DS28E17) driver + * + * Copyright (c) 2016 Jan Kandziora + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CRC16_INIT 0 + +#include + +#define W1_FAMILY_DS28E17 0x19 + +/* Module setup. */ +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Jan Kandziora "); +MODULE_DESCRIPTION("w1 family 19 driver for DS28E17, 1-wire to I2C master bridge"); +MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS28E17)); + + +/* Default I2C speed to be set when a DS28E17 is detected. */ +static int i2c_speed = 100; +module_param_named(speed, i2c_speed, int, (S_IRUSR | S_IWUSR)); +MODULE_PARM_DESC(speed, "Default I2C speed to be set when a DS28E17 is detected"); + +/* Default I2C stretch value to be set when a DS28E17 is detected. */ +static char i2c_stretch = 1; +module_param_named(stretch, i2c_stretch, byte, (S_IRUSR | S_IWUSR)); +MODULE_PARM_DESC(stretch, "Default I2C stretch value to be set when a DS28E17 is detected"); + +/* DS28E17 device command codes. */ +#define W1_F19_WRITE_DATA_WITH_STOP 0x4B +#define W1_F19_WRITE_DATA_NO_STOP 0x5A +#define W1_F19_WRITE_DATA_ONLY 0x69 +#define W1_F19_WRITE_DATA_ONLY_WITH_STOP 0x78 +#define W1_F19_READ_DATA_WITH_STOP 0x87 +#define W1_F19_WRITE_READ_DATA_WITH_STOP 0x2D +#define W1_F19_WRITE_CONFIGURATION 0xD2 +#define W1_F19_READ_CONFIGURATION 0xE1 +#define W1_F19_ENABLE_SLEEP_MODE 0x1E +#define W1_F19_READ_DEVICE_REVISION 0xC4 + +/* DS28E17 status bits */ +#define W1_F19_STATUS_CRC 0x01 +#define W1_F19_STATUS_ADDRESS 0x02 +#define W1_F19_STATUS_START 0x08 + +/* + * Maximum number of I2C bytes to transfer within one CRC16 protected onewire + * command. + * */ +#define W1_F19_WRITE_DATA_LIMIT 255 + +/* Maximum number of I2C bytes to read with one onewire command. */ +#define W1_F19_READ_DATA_LIMIT 255 + +/* Constants for calculating the busy sleep. */ +#define W1_F19_BUSY_TIMEBASES { 90, 23, 10 } +#define W1_F19_BUSY_GRATUITY 1000 + +/* Number of checks for the busy flag before timeout. */ +#define W1_F19_BUSY_CHECKS 1000 + + +/* Slave specific data. */ +struct w1_f19_data { + u8 speed; + u8 stretch; + struct i2c_adapter adapter; +}; + + +/* Wait a while until the busy flag clears. */ +static int w1_f19_i2c_busy_wait(struct w1_slave *sl, size_t count) +{ + const unsigned long timebases[3] = W1_F19_BUSY_TIMEBASES; + struct w1_f19_data *data = sl->family_data; + unsigned int checks; + + /* Check the busy flag first in any case.*/ + if (w1_touch_bit(sl->master, 1) == 0) + return 0; + + /* + * Do a generously long sleep in the beginning, + * as we have to wait at least this time for all + * the I2C bytes at the given speed to be transferred. + */ + usleep_range(timebases[data->speed] * (data->stretch) * count, + timebases[data->speed] * (data->stretch) * count + + W1_F19_BUSY_GRATUITY); + + /* Now continusly check the busy flag sent by the DS28E17. */ + checks = W1_F19_BUSY_CHECKS; + while ((checks--) > 0) { + /* Return success if the busy flag is cleared. */ + if (w1_touch_bit(sl->master, 1) == 0) + return 0; + + /* Wait one non-streched byte timeslot. */ + udelay(timebases[data->speed]); + } + + /* Timeout. */ + dev_warn(&sl->dev, "busy timeout\n"); + return -ETIMEDOUT; +} + + +/* Utility function: result. */ +static size_t w1_f19_error(struct w1_slave *sl, u8 w1_buf[]) +{ + /* Warnings. */ + if (w1_buf[0] & W1_F19_STATUS_CRC) + dev_warn(&sl->dev, "crc16 mismatch\n"); + if (w1_buf[0] & W1_F19_STATUS_ADDRESS) + dev_warn(&sl->dev, "i2c device not responding\n"); + if ((w1_buf[0] & (W1_F19_STATUS_CRC | W1_F19_STATUS_ADDRESS)) == 0 + && w1_buf[1] != 0) { + dev_warn(&sl->dev, "i2c short write, %d bytes not acknowledged\n", + w1_buf[1]); + } + + /* Check error conditions. */ + if (w1_buf[0] & W1_F19_STATUS_ADDRESS) + return -ENXIO; + if (w1_buf[0] & W1_F19_STATUS_START) + return -EAGAIN; + if (w1_buf[0] != 0 || w1_buf[1] != 0) + return -EIO; + + /* All ok. */ + return 0; +} + + +/* Utility function: write data to I2C slave, single chunk. */ +static int __w1_f19_i2c_write(struct w1_slave *sl, + const u8 *command, size_t command_count, + const u8 *buffer, size_t count) +{ + u16 crc; + int error; + u8 w1_buf[2]; + + /* Send command and I2C data to DS28E17. */ + crc = crc16(CRC16_INIT, command, command_count); + w1_write_block(sl->master, command, command_count); + + w1_buf[0] = count; + crc = crc16(crc, w1_buf, 1); + w1_write_8(sl->master, w1_buf[0]); + + crc = crc16(crc, buffer, count); + w1_write_block(sl->master, buffer, count); + + w1_buf[0] = ~(crc & 0xFF); + w1_buf[1] = ~((crc >> 8) & 0xFF); + w1_write_block(sl->master, w1_buf, 2); + + /* Wait until busy flag clears (or timeout). */ + if (w1_f19_i2c_busy_wait(sl, count + 1) < 0) + return -ETIMEDOUT; + + /* Read status from DS28E17. */ + w1_read_block(sl->master, w1_buf, 2); + + /* Check error conditions. */ + error = w1_f19_error(sl, w1_buf); + if (error < 0) + return error; + + /* Return number of bytes written. */ + return count; +} + + +/* Write data to I2C slave. */ +static int w1_f19_i2c_write(struct w1_slave *sl, u16 i2c_address, + const u8 *buffer, size_t count, bool stop) +{ + int result; + int remaining = count; + const u8 *p; + u8 command[2]; + + /* Check input. */ + if (count == 0) + return -EOPNOTSUPP; + + /* Check whether we need multiple commands. */ + if (count <= W1_F19_WRITE_DATA_LIMIT) { + /* + * Small data amount. Data can be sent with + * a single onewire command. + */ + + /* Send all data to DS28E17. */ + command[0] = (stop ? W1_F19_WRITE_DATA_WITH_STOP + : W1_F19_WRITE_DATA_NO_STOP); + command[1] = i2c_address << 1; + result = __w1_f19_i2c_write(sl, command, 2, buffer, count); + } else { + /* Large data amount. Data has to be sent in multiple chunks. */ + + /* Send first chunk to DS28E17. */ + p = buffer; + command[0] = W1_F19_WRITE_DATA_NO_STOP; + command[1] = i2c_address << 1; + result = __w1_f19_i2c_write(sl, command, 2, p, + W1_F19_WRITE_DATA_LIMIT); + if (result < 0) + return result; + + /* Resume to same DS28E17. */ + if (w1_reset_resume_command(sl->master)) + return -EIO; + + /* Next data chunk. */ + p += W1_F19_WRITE_DATA_LIMIT; + remaining -= W1_F19_WRITE_DATA_LIMIT; + + while (remaining > W1_F19_WRITE_DATA_LIMIT) { + /* Send intermediate chunk to DS28E17. */ + command[0] = W1_F19_WRITE_DATA_ONLY; + result = __w1_f19_i2c_write(sl, command, 1, p, + W1_F19_WRITE_DATA_LIMIT); + if (result < 0) + return result; + + /* Resume to same DS28E17. */ + if (w1_reset_resume_command(sl->master)) + return -EIO; + + /* Next data chunk. */ + p += W1_F19_WRITE_DATA_LIMIT; + remaining -= W1_F19_WRITE_DATA_LIMIT; + } + + /* Send final chunk to DS28E17. */ + command[0] = (stop ? W1_F19_WRITE_DATA_ONLY_WITH_STOP + : W1_F19_WRITE_DATA_ONLY); + result = __w1_f19_i2c_write(sl, command, 1, p, remaining); + } + + return result; +} + + +/* Read data from I2C slave. */ +static int w1_f19_i2c_read(struct w1_slave *sl, u16 i2c_address, + u8 *buffer, size_t count) +{ + u16 crc; + int error; + u8 w1_buf[5]; + + /* Check input. */ + if (count == 0) + return -EOPNOTSUPP; + + /* Send command to DS28E17. */ + w1_buf[0] = W1_F19_READ_DATA_WITH_STOP; + w1_buf[1] = i2c_address << 1 | 0x01; + w1_buf[2] = count; + crc = crc16(CRC16_INIT, w1_buf, 3); + w1_buf[3] = ~(crc & 0xFF); + w1_buf[4] = ~((crc >> 8) & 0xFF); + w1_write_block(sl->master, w1_buf, 5); + + /* Wait until busy flag clears (or timeout). */ + if (w1_f19_i2c_busy_wait(sl, count + 1) < 0) + return -ETIMEDOUT; + + /* Read status from DS28E17. */ + w1_buf[0] = w1_read_8(sl->master); + w1_buf[1] = 0; + + /* Check error conditions. */ + error = w1_f19_error(sl, w1_buf); + if (error < 0) + return error; + + /* Read received I2C data from DS28E17. */ + return w1_read_block(sl->master, buffer, count); +} + + +/* Write to, then read data from I2C slave. */ +static int w1_f19_i2c_write_read(struct w1_slave *sl, u16 i2c_address, + const u8 *wbuffer, size_t wcount, u8 *rbuffer, size_t rcount) +{ + u16 crc; + int error; + u8 w1_buf[3]; + + /* Check input. */ + if (wcount == 0 || rcount == 0) + return -EOPNOTSUPP; + + /* Send command and I2C data to DS28E17. */ + w1_buf[0] = W1_F19_WRITE_READ_DATA_WITH_STOP; + w1_buf[1] = i2c_address << 1; + w1_buf[2] = wcount; + crc = crc16(CRC16_INIT, w1_buf, 3); + w1_write_block(sl->master, w1_buf, 3); + + crc = crc16(crc, wbuffer, wcount); + w1_write_block(sl->master, wbuffer, wcount); + + w1_buf[0] = rcount; + crc = crc16(crc, w1_buf, 1); + w1_buf[1] = ~(crc & 0xFF); + w1_buf[2] = ~((crc >> 8) & 0xFF); + w1_write_block(sl->master, w1_buf, 3); + + /* Wait until busy flag clears (or timeout). */ + if (w1_f19_i2c_busy_wait(sl, wcount + rcount + 2) < 0) + return -ETIMEDOUT; + + /* Read status from DS28E17. */ + w1_read_block(sl->master, w1_buf, 2); + + /* Check error conditions. */ + error = w1_f19_error(sl, w1_buf); + if (error < 0) + return error; + + /* Read received I2C data from DS28E17. */ + return w1_read_block(sl->master, rbuffer, rcount); +} + + +/* Do an I2C master transfer. */ +static int w1_f19_i2c_master_transfer(struct i2c_adapter *adapter, + struct i2c_msg *msgs, int num) +{ + struct w1_slave *sl = (struct w1_slave *) adapter->algo_data; + int i = 0; + int result = 0; + + /* Start onewire transaction. */ + mutex_lock(&sl->master->bus_mutex); + + /* Select DS28E17. */ + if (w1_reset_select_slave(sl)) { + i = -EIO; + goto error; + } + + /* Loop while there are still messages to transfer. */ + while (i < num) { + /* + * Check for special case: Small write followed + * by read to same I2C device. + */ + if (i < (num-1) + && msgs[i].addr == msgs[i+1].addr + && !(msgs[i].flags & I2C_M_RD) + && (msgs[i+1].flags & I2C_M_RD) + && (msgs[i].len <= W1_F19_WRITE_DATA_LIMIT)) { + /* + * The DS28E17 has a combined transfer + * for small write+read. + */ + result = w1_f19_i2c_write_read(sl, msgs[i].addr, + msgs[i].buf, msgs[i].len, + msgs[i+1].buf, msgs[i+1].len); + if (result < 0) { + i = result; + goto error; + } + + /* + * Check if we should interpret the read data + * as a length byte. The DS28E17 unfortunately + * has no read without stop, so we can just do + * another simple read in that case. + */ + if (msgs[i+1].flags & I2C_M_RECV_LEN) { + result = w1_f19_i2c_read(sl, msgs[i+1].addr, + &(msgs[i+1].buf[1]), msgs[i+1].buf[0]); + if (result < 0) { + i = result; + goto error; + } + } + + /* Eat up read message, too. */ + i++; + } else if (msgs[i].flags & I2C_M_RD) { + /* Read transfer. */ + result = w1_f19_i2c_read(sl, msgs[i].addr, + msgs[i].buf, msgs[i].len); + if (result < 0) { + i = result; + goto error; + } + + /* + * Check if we should interpret the read data + * as a length byte. The DS28E17 unfortunately + * has no read without stop, so we can just do + * another simple read in that case. + */ + if (msgs[i].flags & I2C_M_RECV_LEN) { + result = w1_f19_i2c_read(sl, + msgs[i].addr, + &(msgs[i].buf[1]), + msgs[i].buf[0]); + if (result < 0) { + i = result; + goto error; + } + } + } else { + /* + * Write transfer. + * Stop condition only for last + * transfer. + */ + result = w1_f19_i2c_write(sl, + msgs[i].addr, + msgs[i].buf, + msgs[i].len, + i == (num-1)); + if (result < 0) { + i = result; + goto error; + } + } + + /* Next message. */ + i++; + + /* Are there still messages to send/receive? */ + if (i < num) { + /* Yes. Resume to same DS28E17. */ + if (w1_reset_resume_command(sl->master)) { + i = -EIO; + goto error; + } + } + } + +error: + /* End onewire transaction. */ + mutex_unlock(&sl->master->bus_mutex); + + /* Return number of messages processed or error. */ + return i; +} + + +/* Get I2C adapter functionality. */ +static u32 w1_f19_i2c_functionality(struct i2c_adapter *adapter) +{ + /* + * Plain I2C functions only. + * SMBus is emulated by the kernel's I2C layer. + * No "I2C_FUNC_SMBUS_QUICK" + * No "I2C_FUNC_SMBUS_READ_BLOCK_DATA" + * No "I2C_FUNC_SMBUS_BLOCK_PROC_CALL" + */ + return I2C_FUNC_I2C | + I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_PROC_CALL | + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | + I2C_FUNC_SMBUS_I2C_BLOCK | + I2C_FUNC_SMBUS_PEC; +} + + +/* I2C adapter quirks. */ +static const struct i2c_adapter_quirks w1_f19_i2c_adapter_quirks = { + .max_read_len = W1_F19_READ_DATA_LIMIT, +}; + +/* I2C algorithm. */ +static const struct i2c_algorithm w1_f19_i2c_algorithm = { + .master_xfer = w1_f19_i2c_master_transfer, + .functionality = w1_f19_i2c_functionality, +}; + + +/* Read I2C speed from DS28E17. */ +static int w1_f19_get_i2c_speed(struct w1_slave *sl) +{ + struct w1_f19_data *data = sl->family_data; + int result = -EIO; + + /* Start onewire transaction. */ + mutex_lock(&sl->master->bus_mutex); + + /* Select slave. */ + if (w1_reset_select_slave(sl)) + goto error; + + /* Read slave configuration byte. */ + w1_write_8(sl->master, W1_F19_READ_CONFIGURATION); + result = w1_read_8(sl->master); + if (result < 0 || result > 2) { + result = -EIO; + goto error; + } + + /* Update speed in slave specific data. */ + data->speed = result; + +error: + /* End onewire transaction. */ + mutex_unlock(&sl->master->bus_mutex); + + return result; +} + + +/* Set I2C speed on DS28E17. */ +static int __w1_f19_set_i2c_speed(struct w1_slave *sl, u8 speed) +{ + struct w1_f19_data *data = sl->family_data; + const int i2c_speeds[3] = { 100, 400, 900 }; + u8 w1_buf[2]; + + /* Select slave. */ + if (w1_reset_select_slave(sl)) + return -EIO; + + w1_buf[0] = W1_F19_WRITE_CONFIGURATION; + w1_buf[1] = speed; + w1_write_block(sl->master, w1_buf, 2); + + /* Update speed in slave specific data. */ + data->speed = speed; + + dev_info(&sl->dev, "i2c speed set to %d kBaud\n", i2c_speeds[speed]); + + return 0; +} + +static int w1_f19_set_i2c_speed(struct w1_slave *sl, u8 speed) +{ + int result; + + /* Start onewire transaction. */ + mutex_lock(&sl->master->bus_mutex); + + /* Set I2C speed on DS28E17. */ + result = __w1_f19_set_i2c_speed(sl, speed); + + /* End onewire transaction. */ + mutex_unlock(&sl->master->bus_mutex); + + return result; +} + + +/* Sysfs attributes. */ + +/* I2C speed attribute for a single chip. */ +static ssize_t speed_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct w1_slave *sl = dev_to_w1_slave(dev); + int result; + + /* Read current speed from slave. Updates data->speed. */ + result = w1_f19_get_i2c_speed(sl); + if (result < 0) + return result; + + /* Return current speed value. */ + return sprintf(buf, "%d\n", result); +} + +static ssize_t speed_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct w1_slave *sl = dev_to_w1_slave(dev); + int error; + + /* Valid values are: "100", "400", "900" */ + if (count < 3 || count > 4 || !buf) + return -EINVAL; + if (count == 4 && buf[3] != '\n') + return -EINVAL; + if (buf[1] != '0' || buf[2] != '0') + return -EINVAL; + + /* Set speed on slave. */ + switch (buf[0]) { + case '1': + error = w1_f19_set_i2c_speed(sl, 0); + break; + case '4': + error = w1_f19_set_i2c_speed(sl, 1); + break; + case '9': + error = w1_f19_set_i2c_speed(sl, 2); + break; + default: + return -EINVAL; + } + + if (error < 0) + return error; + + /* Return bytes written. */ + return count; +} + +static DEVICE_ATTR_RW(speed); + + +/* Busy stretch attribute for a single chip. */ +static ssize_t stretch_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct w1_slave *sl = dev_to_w1_slave(dev); + struct w1_f19_data *data = sl->family_data; + + /* Return current stretch value. */ + return sprintf(buf, "%d\n", data->stretch); +} + +static ssize_t stretch_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct w1_slave *sl = dev_to_w1_slave(dev); + struct w1_f19_data *data = sl->family_data; + + /* Valid values are '1' to '9' */ + if (count < 1 || count > 2 || !buf) + return -EINVAL; + if (count == 2 && buf[1] != '\n') + return -EINVAL; + if (buf[0] < '1' || buf[0] > '9') + return -EINVAL; + + /* Set busy stretch value. */ + data->stretch = buf[0] & 0x0F; + + /* Return bytes written. */ + return count; +} + +static DEVICE_ATTR_RW(stretch); + + +/* All attributes. */ +static struct attribute *w1_f19_attrs[] = { + &dev_attr_speed.attr, + &dev_attr_stretch.attr, + NULL, +}; + +static const struct attribute_group w1_f19_group = { + .attrs = w1_f19_attrs, +}; + +static const struct attribute_group *w1_f19_groups[] = { + &w1_f19_group, + NULL, +}; + + +/* Slave add and remove functions. */ +static int w1_f19_add_slave(struct w1_slave *sl) +{ + struct w1_f19_data *data = NULL; + + /* Allocate memory for slave specific data. */ + data = devm_kzalloc(&sl->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + sl->family_data = data; + + /* Setup default I2C speed on slave. */ + switch (i2c_speed) { + case 100: + __w1_f19_set_i2c_speed(sl, 0); + break; + case 400: + __w1_f19_set_i2c_speed(sl, 1); + break; + case 900: + __w1_f19_set_i2c_speed(sl, 2); + break; + default: + /* + * A i2c_speed module parameter of anything else + * than 100, 400, 900 means not to touch the + * speed of the DS28E17. + * We assume 400kBaud, the power-on value. + */ + data->speed = 1; + } + + /* + * Setup default busy stretch + * configuration for the DS28E17. + */ + data->stretch = i2c_stretch; + + /* Setup I2C adapter. */ + data->adapter.owner = THIS_MODULE; + data->adapter.algo = &w1_f19_i2c_algorithm; + data->adapter.algo_data = sl; + strcpy(data->adapter.name, "w1-"); + strcat(data->adapter.name, sl->name); + data->adapter.dev.parent = &sl->dev; + data->adapter.quirks = &w1_f19_i2c_adapter_quirks; + + return i2c_add_adapter(&data->adapter); +} + +static void w1_f19_remove_slave(struct w1_slave *sl) +{ + struct w1_f19_data *family_data = sl->family_data; + + /* Delete I2C adapter. */ + i2c_del_adapter(&family_data->adapter); + + /* Free slave specific data. */ + devm_kfree(&sl->dev, family_data); + sl->family_data = NULL; +} + + +/* Declarations within the w1 subsystem. */ +static struct w1_family_ops w1_f19_fops = { + .add_slave = w1_f19_add_slave, + .remove_slave = w1_f19_remove_slave, + .groups = w1_f19_groups, +}; + +static struct w1_family w1_family_19 = { + .fid = W1_FAMILY_DS28E17, + .fops = &w1_f19_fops, +}; + + +/* Module init and remove functions. */ +static int __init w1_f19_init(void) +{ + return w1_register_family(&w1_family_19); +} + +static void __exit w1_f19_fini(void) +{ + w1_unregister_family(&w1_family_19); +} + +module_init(w1_f19_init); +module_exit(w1_f19_fini); + -- cgit v1.2.3-58-ga151 From bd14798650cd2a2befd7d96bbc466c2317a582db Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 30 Sep 2017 14:27:41 +0300 Subject: vme: Fix integer overflow checking in vme_check_window() The controversial part of this patch is that I've changed it so we now prevent integer overflows for VME_USER types and before we didn't. I view it as kernel-hardening. I looked at a couple places that used VME_USER types and they seemed pretty suspicious so I'm pretty sure preventing overflows here is a good idea. The most common problem which this function is for cases like VME_A16 where we don't put an upper bound on "size" so you could have "size" set to U64_MAX and a valid vme_base would overflow the "vme_base + size" into the valid range as well. In the VME_A64 case, the integer overflow checking doesn't work because "U64_MAX + 1" has an integer overflow and it's just a complicated way of saying zero. That VME_A64 case is sort of interesting as well because there is a VME_A64_MAX define which is set to "U64_MAX + 1". The compiler will never let anyone use it since it can't be stored in a u64 variable... With my patch it's now limited to just U64_MAX. Anyway, I put one integer overflow check at the start of the function and deleted all existing checks. Signed-off-by: Dan Carpenter Acked-by: Dmitry Kalinkin Signed-off-by: Greg Kroah-Hartman --- drivers/vme/vme.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index 6a3ead42aba8..5b4c898d7509 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -208,29 +208,27 @@ int vme_check_window(u32 aspace, unsigned long long vme_base, { int retval = 0; + if (vme_base + size < size) + return -EINVAL; + switch (aspace) { case VME_A16: - if (((vme_base + size) > VME_A16_MAX) || - (vme_base > VME_A16_MAX)) + if (vme_base + size > VME_A16_MAX) retval = -EFAULT; break; case VME_A24: - if (((vme_base + size) > VME_A24_MAX) || - (vme_base > VME_A24_MAX)) + if (vme_base + size > VME_A24_MAX) retval = -EFAULT; break; case VME_A32: - if (((vme_base + size) > VME_A32_MAX) || - (vme_base > VME_A32_MAX)) + if (vme_base + size > VME_A32_MAX) retval = -EFAULT; break; case VME_A64: - if ((size != 0) && (vme_base > U64_MAX + 1 - size)) - retval = -EFAULT; + /* The VME_A64_MAX limit is actually U64_MAX + 1 */ break; case VME_CRCSR: - if (((vme_base + size) > VME_CRCSR_MAX) || - (vme_base > VME_CRCSR_MAX)) + if (vme_base + size > VME_CRCSR_MAX) retval = -EFAULT; break; case VME_USER1: -- cgit v1.2.3-58-ga151 From 988437aec0e517f683b2491d43aa1cb4b231f8b8 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Sun, 17 Sep 2017 12:33:43 +0200 Subject: nvmem: add snvs_lpgpr driver This is a driver for Low Power General Purpose Register (LPGPR) available on i.MX6 SoCs in Secure Non-Volatile Storage (SNVS) of this chip. It is a 32-bit read/write register located in the low power domain. Since LPGPR is located in the battery-backed power domain, LPGPR can be used by any application for retaining data during an SoC power-down mode. Signed-off-by: Oleksij Rempel Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/Kconfig | 10 +++ drivers/nvmem/Makefile | 2 + drivers/nvmem/snvs_lpgpr.c | 156 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 drivers/nvmem/snvs_lpgpr.c (limited to 'drivers') diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 101ced4c84be..ea3044c5d6ee 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -144,4 +144,14 @@ config MESON_EFUSE This driver can also be built as a module. If so, the module will be called nvmem_meson_efuse. +config NVMEM_SNVS_LPGPR + tristate "Support for Low Power General Purpose Register" + depends on SOC_IMX6 || COMPILE_TEST + help + This is a driver for Low Power General Purpose Register (LPGPR) available on + i.MX6 SoCs in Secure Non-Volatile Storage (SNVS) of this chip. + + This driver can also be built as a module. If so, the module + will be called nvmem-snvs-lpgpr. + endif diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 173140658693..4c589184acee 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -30,3 +30,5 @@ obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o nvmem-vf610-ocotp-y := vf610-ocotp.o obj-$(CONFIG_MESON_EFUSE) += nvmem_meson_efuse.o nvmem_meson_efuse-y := meson-efuse.o +obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o +nvmem_snvs_lpgpr-y := snvs_lpgpr.o diff --git a/drivers/nvmem/snvs_lpgpr.c b/drivers/nvmem/snvs_lpgpr.c new file mode 100644 index 000000000000..e5c2a4a17f03 --- /dev/null +++ b/drivers/nvmem/snvs_lpgpr.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2015 Pengutronix, Steffen Trumtrar + * Copyright (c) 2017 Pengutronix, Oleksij Rempel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#define IMX6Q_SNVS_HPLR 0x00 +#define IMX6Q_GPR_SL BIT(5) +#define IMX6Q_SNVS_LPLR 0x34 +#define IMX6Q_GPR_HL BIT(5) +#define IMX6Q_SNVS_LPGPR 0x68 + +struct snvs_lpgpr_cfg { + int offset; + int offset_hplr; + int offset_lplr; +}; + +struct snvs_lpgpr_priv { + struct device_d *dev; + struct regmap *regmap; + struct nvmem_config cfg; + const struct snvs_lpgpr_cfg *dcfg; +}; + +static const struct snvs_lpgpr_cfg snvs_lpgpr_cfg_imx6q = { + .offset = IMX6Q_SNVS_LPGPR, + .offset_hplr = IMX6Q_SNVS_HPLR, + .offset_lplr = IMX6Q_SNVS_LPLR, +}; + +static int snvs_lpgpr_write(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct snvs_lpgpr_priv *priv = context; + const struct snvs_lpgpr_cfg *dcfg = priv->dcfg; + unsigned int lock_reg; + int ret; + + ret = regmap_read(priv->regmap, dcfg->offset_hplr, &lock_reg); + if (ret < 0) + return ret; + + if (lock_reg & IMX6Q_GPR_SL) + return -EPERM; + + ret = regmap_read(priv->regmap, dcfg->offset_lplr, &lock_reg); + if (ret < 0) + return ret; + + if (lock_reg & IMX6Q_GPR_HL) + return -EPERM; + + return regmap_bulk_write(priv->regmap, dcfg->offset + offset, val, + bytes / 4); +} + +static int snvs_lpgpr_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct snvs_lpgpr_priv *priv = context; + const struct snvs_lpgpr_cfg *dcfg = priv->dcfg; + + return regmap_bulk_read(priv->regmap, dcfg->offset + offset, + val, bytes / 4); +} + +static int snvs_lpgpr_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; + struct device_node *syscon_node; + struct snvs_lpgpr_priv *priv; + struct nvmem_config *cfg; + struct nvmem_device *nvmem; + const struct snvs_lpgpr_cfg *dcfg; + + if (!node) + return -ENOENT; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + dcfg = of_device_get_match_data(dev); + if (!dcfg) + return -EINVAL; + + syscon_node = of_get_parent(node); + if (!syscon_node) + return -ENODEV; + + priv->regmap = syscon_node_to_regmap(syscon_node); + of_node_put(syscon_node); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + priv->dcfg = dcfg; + + cfg = &priv->cfg; + cfg->priv = priv; + cfg->name = dev_name(dev); + cfg->dev = dev; + cfg->stride = 4, + cfg->word_size = 4, + cfg->size = 4, + cfg->owner = THIS_MODULE, + cfg->reg_read = snvs_lpgpr_read, + cfg->reg_write = snvs_lpgpr_write, + + nvmem = nvmem_register(cfg); + if (IS_ERR(nvmem)) + return PTR_ERR(nvmem); + + platform_set_drvdata(pdev, nvmem); + + return 0; +} + +static int snvs_lpgpr_remove(struct platform_device *pdev) +{ + struct nvmem_device *nvmem = platform_get_drvdata(pdev); + + return nvmem_unregister(nvmem); +} + +static const struct of_device_id snvs_lpgpr_dt_ids[] = { + { .compatible = "fsl,imx6q-snvs-lpgpr", .data = &snvs_lpgpr_cfg_imx6q }, + { .compatible = "fsl,imx6ul-snvs-lpgpr", + .data = &snvs_lpgpr_cfg_imx6q }, + { }, +}; +MODULE_DEVICE_TABLE(of, snvs_lpgpr_dt_ids); + +static struct platform_driver snvs_lpgpr_driver = { + .probe = snvs_lpgpr_probe, + .remove = snvs_lpgpr_remove, + .driver = { + .name = "snvs_lpgpr", + .of_match_table = snvs_lpgpr_dt_ids, + }, +}; +module_platform_driver(snvs_lpgpr_driver); + +MODULE_AUTHOR("Oleksij Rempel "); +MODULE_DESCRIPTION("Low Power General Purpose Register in i.MX6 Secure Non-Volatile Storage"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-58-ga151 From ed50a0890eaa8b4468097644b11a61a5f313860c Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 3 Oct 2017 09:31:45 +0100 Subject: drivers/fsi: make a couple of functions static The functions fsi_slave_report_and_clear_errors and fsi_slave_handle_error are local to the source and do not need to be in global scope, so make them static. Cleans up sparse warnings: symbol 'fsi_slave_report_and_clear_errors' was not declared. Should it be static? symbol 'fsi_slave_handle_error' was not declared. Should it be static? Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman --- drivers/fsi/fsi-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index 4ea63d9bd131..e318bf8c623c 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -185,7 +185,7 @@ static int fsi_slave_calc_addr(struct fsi_slave *slave, uint32_t *addrp, return 0; } -int fsi_slave_report_and_clear_errors(struct fsi_slave *slave) +static int fsi_slave_report_and_clear_errors(struct fsi_slave *slave) { struct fsi_master *master = slave->master; uint32_t irq, stat; @@ -215,8 +215,8 @@ int fsi_slave_report_and_clear_errors(struct fsi_slave *slave) static int fsi_slave_set_smode(struct fsi_master *master, int link, int id); -int fsi_slave_handle_error(struct fsi_slave *slave, bool write, uint32_t addr, - size_t size) +static int fsi_slave_handle_error(struct fsi_slave *slave, bool write, + uint32_t addr, size_t size) { struct fsi_master *master = slave->master; int rc, link; -- cgit v1.2.3-58-ga151 From d8d9d936464a9b61c0e6cb1ff7c831a9cbd2f228 Mon Sep 17 00:00:00 2001 From: Bhumika Goyal Date: Thu, 21 Sep 2017 09:52:41 -0500 Subject: fpga: make xlnx_pr_decoupler_br_ops const Make this const as it is only passed to a const argument of the function fpga_bridge_register. Signed-off-by: Bhumika Goyal Acked-by: Michal Simek Acked-by: Moritz Fischer Signed-off-by: Alan Tull Signed-off-by: Greg Kroah-Hartman --- drivers/fpga/xilinx-pr-decoupler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/fpga/xilinx-pr-decoupler.c b/drivers/fpga/xilinx-pr-decoupler.c index e359930bebc8..0d7743089414 100644 --- a/drivers/fpga/xilinx-pr-decoupler.c +++ b/drivers/fpga/xilinx-pr-decoupler.c @@ -79,7 +79,7 @@ static int xlnx_pr_decoupler_enable_show(struct fpga_bridge *bridge) return !status; } -static struct fpga_bridge_ops xlnx_pr_decoupler_br_ops = { +static const struct fpga_bridge_ops xlnx_pr_decoupler_br_ops = { .enable_set = xlnx_pr_decoupler_enable_set, .enable_show = xlnx_pr_decoupler_enable_show, }; -- cgit v1.2.3-58-ga151 From 378f79cab12b669928f3a4037f023837ead2ce0c Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 30 Sep 2017 11:15:52 +0300 Subject: misc: pci_endpoint_test: Prevent some integer overflows "size + max" can have an arithmetic overflow when we're allocating: orig_src_addr = dma_alloc_coherent(dev, size + alignment, ... I've added a few checks to prevent that. Fixes: 13107c60681f ("misc: pci_endpoint_test: Add support to provide aligned buffer addresses") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pci_endpoint_test.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers') diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index deb203026496..c0d323077ad0 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -226,6 +226,9 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size) u32 src_crc32; u32 dst_crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_src_addr = dma_alloc_coherent(dev, size + alignment, &orig_src_phys_addr, GFP_KERNEL); if (!orig_src_addr) { @@ -311,6 +314,9 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size) size_t alignment = test->alignment; u32 crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, GFP_KERNEL); if (!orig_addr) { @@ -369,6 +375,9 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size) size_t alignment = test->alignment; u32 crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, GFP_KERNEL); if (!orig_addr) { -- cgit v1.2.3-58-ga151 From 846df244ebefbc9f7b91e9ae7a5e5a2e69fb4772 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 30 Sep 2017 11:16:51 +0300 Subject: misc: pci_endpoint_test: Avoid triggering a BUG() If you call ida_simple_remove(&pci_endpoint_test_ida, id) with a negative "id" then it triggers an immediate BUG_ON(). Let's not allow that. Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pci_endpoint_test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index c0d323077ad0..d40a34f594c7 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -597,6 +597,8 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) != 1) return; + if (id < 0) + return; misc_deregister(&test->miscdev); ida_simple_remove(&pci_endpoint_test_ida, id); -- cgit v1.2.3-58-ga151 From c151206b30466a787fa85564eec43b5b7a4f9175 Mon Sep 17 00:00:00 2001 From: Bhumika Goyal Date: Sat, 30 Sep 2017 22:29:54 +0530 Subject: pcmcia: make pccard_cis_attr const Make this const as it is only passed to the const arguments of the functions sysfs_remove_bin_file and sysfs_create_bin_file. Make the declaration const too. Structure found using Coccinelle and changes done by hand. Signed-off-by: Bhumika Goyal Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/cistpl.c | 2 +- drivers/pcmcia/cs_internal.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 55ef7d1fd8da..102646fedb56 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -1599,7 +1599,7 @@ static ssize_t pccard_store_cis(struct file *filp, struct kobject *kobj, } -struct bin_attribute pccard_cis_attr = { +const struct bin_attribute pccard_cis_attr = { .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, .size = 0x200, .read = pccard_show_cis, diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index e86cd6b31773..6765beadea95 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -152,7 +152,7 @@ void pcmcia_cleanup_irq(struct pcmcia_socket *s); int pcmcia_setup_irq(struct pcmcia_device *p_dev); /* cistpl.c */ -extern struct bin_attribute pccard_cis_attr; +extern const struct bin_attribute pccard_cis_attr; int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, u_int len, void *ptr); -- cgit v1.2.3-58-ga151 From 06b6f1c623122bcf28f5a75b89862a68b9c884eb Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 21 Sep 2017 16:26:29 -0700 Subject: misc: altera-stapl: drop Kconfig comment When I2C is enabled, the comment string for "Altera FPGA firmware download module" adds no new information or value. It is only useful and interesting when I2C is not enabled. In that case, have it show that I2C is needed for that module. Signed-off-by: Randy Dunlap Cc: Igor M. Liplianin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/altera-stapl/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/misc/altera-stapl/Kconfig b/drivers/misc/altera-stapl/Kconfig index 7f01d8e93992..8a828fe41fad 100644 --- a/drivers/misc/altera-stapl/Kconfig +++ b/drivers/misc/altera-stapl/Kconfig @@ -1,4 +1,5 @@ -comment "Altera FPGA firmware download module" +comment "Altera FPGA firmware download module (requires I2C)" + depends on !I2C config ALTERA_STAPL tristate "Altera FPGA firmware download module" -- cgit v1.2.3-58-ga151 From 876a1b08d0f9d7df406f702a9aba0e058500efac Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sun, 24 Sep 2017 11:16:18 -0700 Subject: misc: mic: move to its own menu in Misc devices Move the Intel MIC drivers into their own menu. This is due to the number of drivers (Kconfig entries) here and it simplifies (cleans up) the "Misc devices" menu. Signed-off-by: Randy Dunlap Cc: Sudeep Dutt Cc: Ashutosh Dixit Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mic/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers') diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig index 6fd9d367dea7..227cc7443671 100644 --- a/drivers/misc/mic/Kconfig +++ b/drivers/misc/mic/Kconfig @@ -1,3 +1,5 @@ +menu "Intel MIC & related support" + comment "Intel MIC Bus Driver" config INTEL_MIC_BUS @@ -150,3 +152,5 @@ config VOP if VOP source "drivers/vhost/Kconfig.vringh" endif + +endmenu -- cgit v1.2.3-58-ga151 From c2e5df616e1ae6c2a074cb241ebb65a318ebaf7c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 21 Sep 2017 20:58:49 -0700 Subject: vmbus: add per-channel sysfs info This extends existing vmbus related sysfs structure to provide per-channel state information. This is useful when diagnosing issues with multiple queues in networking and storage. The existing sysfs only displayed information about the primary channel. The one place it reported multiple channels was the channel_vp_mapping file which violated the sysfs convention of one value per file. Signed-off-by: Stephen Hemminger Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/stable/sysfs-bus-vmbus | 56 ++++++++++ drivers/hv/channel_mgmt.c | 10 +- drivers/hv/hyperv_vmbus.h | 2 + drivers/hv/vmbus_drv.c | 185 +++++++++++++++++++++++++++++-- include/linux/hyperv.h | 6 + 5 files changed, 246 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus index 5d0125f7bcaf..0ebd8a1537a0 100644 --- a/Documentation/ABI/stable/sysfs-bus-vmbus +++ b/Documentation/ABI/stable/sysfs-bus-vmbus @@ -41,3 +41,59 @@ KernelVersion: 4.5 Contact: K. Y. Srinivasan Description: The 16 bit vendor ID of the device Users: tools/hv/lsvmbus and user level RDMA libraries + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: VCPU (sub)channel is affinitized to +Users: tools/hv/lsvmbus and other debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: VCPU (sub)channel is affinitized to +Users: tools/hv/lsvmbus and other debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/in_mask +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Inbound channel signaling state +Users: Debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Channel signaling latency +Users: Debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Outbound channel signaling state +Users: Debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Channel interrupt pending state +Users: Debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Bytes availabble to read +Users: Debuggig tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Bytes availabble to write +Users: Debuggig tools diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 060df71c2e8b..dd2dffe816be 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -350,7 +350,7 @@ static void free_channel(struct vmbus_channel *channel) { tasklet_kill(&channel->callback_event); - kfree_rcu(channel, rcu); + kobject_put(&channel->kobj); } static void percpu_channel_enq(void *arg) @@ -513,6 +513,14 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel) newchannel->state = CHANNEL_OPEN_STATE; if (!fnew) { + struct hv_device *dev + = newchannel->primary_channel->device_obj; + + if (vmbus_add_channel_kobj(dev, newchannel)) { + atomic_dec(&vmbus_connection.offer_in_progress); + goto err_free_chan; + } + if (channel->sc_creation_callback != NULL) channel->sc_creation_callback(newchannel); return; diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 49569f8fe038..de6f01df9592 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -373,6 +373,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type, int vmbus_device_register(struct hv_device *child_device_obj); void vmbus_device_unregister(struct hv_device *device_obj); +int vmbus_add_channel_kobj(struct hv_device *device_obj, + struct vmbus_channel *channel); struct vmbus_channel *relid2channel(u32 relid); diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index a9d49f6f6501..a209527b09f5 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -107,28 +107,30 @@ static void print_alias_name(struct hv_device *hv_dev, char *alias_name) sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]); } -static u8 channel_monitor_group(struct vmbus_channel *channel) +static u8 channel_monitor_group(const struct vmbus_channel *channel) { return (u8)channel->offermsg.monitorid / 32; } -static u8 channel_monitor_offset(struct vmbus_channel *channel) +static u8 channel_monitor_offset(const struct vmbus_channel *channel) { return (u8)channel->offermsg.monitorid % 32; } -static u32 channel_pending(struct vmbus_channel *channel, - struct hv_monitor_page *monitor_page) +static u32 channel_pending(const struct vmbus_channel *channel, + const struct hv_monitor_page *monitor_page) { u8 monitor_group = channel_monitor_group(channel); + return monitor_page->trigger_group[monitor_group].pending; } -static u32 channel_latency(struct vmbus_channel *channel, - struct hv_monitor_page *monitor_page) +static u32 channel_latency(const struct vmbus_channel *channel, + const struct hv_monitor_page *monitor_page) { u8 monitor_group = channel_monitor_group(channel); u8 monitor_offset = channel_monitor_offset(channel); + return monitor_page->latency[monitor_group][monitor_offset]; } @@ -1134,6 +1136,145 @@ void vmbus_driver_unregister(struct hv_driver *hv_driver) } EXPORT_SYMBOL_GPL(vmbus_driver_unregister); + +/* + * Called when last reference to channel is gone. + */ +static void vmbus_chan_release(struct kobject *kobj) +{ + struct vmbus_channel *channel + = container_of(kobj, struct vmbus_channel, kobj); + + kfree_rcu(channel, rcu); +} + +struct vmbus_chan_attribute { + struct attribute attr; + ssize_t (*show)(const struct vmbus_channel *chan, char *buf); + ssize_t (*store)(struct vmbus_channel *chan, + const char *buf, size_t count); +}; +#define VMBUS_CHAN_ATTR(_name, _mode, _show, _store) \ + struct vmbus_chan_attribute chan_attr_##_name \ + = __ATTR(_name, _mode, _show, _store) +#define VMBUS_CHAN_ATTR_RW(_name) \ + struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RW(_name) +#define VMBUS_CHAN_ATTR_RO(_name) \ + struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RO(_name) +#define VMBUS_CHAN_ATTR_WO(_name) \ + struct vmbus_chan_attribute chan_attr_##_name = __ATTR_WO(_name) + +static ssize_t vmbus_chan_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + const struct vmbus_chan_attribute *attribute + = container_of(attr, struct vmbus_chan_attribute, attr); + const struct vmbus_channel *chan + = container_of(kobj, struct vmbus_channel, kobj); + + if (!attribute->show) + return -EIO; + + return attribute->show(chan, buf); +} + +static const struct sysfs_ops vmbus_chan_sysfs_ops = { + .show = vmbus_chan_attr_show, +}; + +static ssize_t out_mask_show(const struct vmbus_channel *channel, char *buf) +{ + const struct hv_ring_buffer_info *rbi = &channel->outbound; + + return sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); +} +VMBUS_CHAN_ATTR_RO(out_mask); + +static ssize_t in_mask_show(const struct vmbus_channel *channel, char *buf) +{ + const struct hv_ring_buffer_info *rbi = &channel->inbound; + + return sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); +} +VMBUS_CHAN_ATTR_RO(in_mask); + +static ssize_t read_avail_show(const struct vmbus_channel *channel, char *buf) +{ + const struct hv_ring_buffer_info *rbi = &channel->inbound; + + return sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi)); +} +VMBUS_CHAN_ATTR_RO(read_avail); + +static ssize_t write_avail_show(const struct vmbus_channel *channel, char *buf) +{ + const struct hv_ring_buffer_info *rbi = &channel->outbound; + + return sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi)); +} +VMBUS_CHAN_ATTR_RO(write_avail); + +static ssize_t show_target_cpu(const struct vmbus_channel *channel, char *buf) +{ + return sprintf(buf, "%u\n", channel->target_cpu); +} +VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL); + +static ssize_t channel_pending_show(const struct vmbus_channel *channel, + char *buf) +{ + return sprintf(buf, "%d\n", + channel_pending(channel, + vmbus_connection.monitor_pages[1])); +} +VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL); + +static ssize_t channel_latency_show(const struct vmbus_channel *channel, + char *buf) +{ + return sprintf(buf, "%d\n", + channel_latency(channel, + vmbus_connection.monitor_pages[1])); +} +VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL); + +static struct attribute *vmbus_chan_attrs[] = { + &chan_attr_out_mask.attr, + &chan_attr_in_mask.attr, + &chan_attr_read_avail.attr, + &chan_attr_write_avail.attr, + &chan_attr_cpu.attr, + &chan_attr_pending.attr, + &chan_attr_latency.attr, + NULL +}; + +static struct kobj_type vmbus_chan_ktype = { + .sysfs_ops = &vmbus_chan_sysfs_ops, + .release = vmbus_chan_release, + .default_attrs = vmbus_chan_attrs, +}; + +/* + * vmbus_add_channel_kobj - setup a sub-directory under device/channels + */ +int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) +{ + struct kobject *kobj = &channel->kobj; + u32 relid = channel->offermsg.child_relid; + int ret; + + kobj->kset = dev->channels_kset; + ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, + "%u", relid); + if (ret) + return ret; + + kobject_uevent(kobj, KOBJ_ADD); + + return 0; +} + /* * vmbus_device_create - Creates and registers a new child device * on the vmbus. @@ -1165,7 +1306,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type, */ int vmbus_device_register(struct hv_device *child_device_obj) { - int ret = 0; + struct kobject *kobj = &child_device_obj->device.kobj; + int ret; dev_set_name(&child_device_obj->device, "%pUl", child_device_obj->channel->offermsg.offer.if_instance.b); @@ -1179,13 +1321,32 @@ int vmbus_device_register(struct hv_device *child_device_obj) * binding...which will eventually call vmbus_match() and vmbus_probe() */ ret = device_register(&child_device_obj->device); - - if (ret) + if (ret) { pr_err("Unable to register child device\n"); - else - pr_debug("child device %s registered\n", - dev_name(&child_device_obj->device)); + return ret; + } + + child_device_obj->channels_kset = kset_create_and_add("channels", + NULL, kobj); + if (!child_device_obj->channels_kset) { + ret = -ENOMEM; + goto err_dev_unregister; + } + + ret = vmbus_add_channel_kobj(child_device_obj, + child_device_obj->channel); + if (ret) { + pr_err("Unable to register primary channeln"); + goto err_kset_unregister; + } + + return 0; + +err_kset_unregister: + kset_unregister(child_device_obj->channels_kset); +err_dev_unregister: + device_unregister(&child_device_obj->device); return ret; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index c458d7b7ad19..ef16ee039850 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -828,6 +828,11 @@ struct vmbus_channel { */ struct rcu_head rcu; + /* + * For sysfs per-channel properties. + */ + struct kobject kobj; + /* * For performance critical channels (storage, networking * etc,), Hyper-V has a mechanism to enhance the throughput @@ -1089,6 +1094,7 @@ struct hv_device { struct device device; struct vmbus_channel *channel; + struct kset *channels_kset; }; -- cgit v1.2.3-58-ga151 From 94eefcc1cb648a6a14fe0d7a79da48d0a33ca781 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 24 Aug 2017 21:38:20 +0200 Subject: vme: Delete 11 error messages for a failed memory allocation Omit extra messages for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/vme.c | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index 6a3ead42aba8..53e87af8e0b8 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -337,10 +337,9 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, goto err_image; resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); - if (resource == NULL) { - printk(KERN_WARNING "Unable to allocate resource structure\n"); + if (!resource) goto err_alloc; - } + resource->type = VME_SLAVE; resource->entry = &allocated_image->list; @@ -542,10 +541,9 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, } resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); - if (resource == NULL) { - printk(KERN_ERR "Unable to allocate resource structure\n"); + if (!resource) goto err_alloc; - } + resource->type = VME_MASTER; resource->entry = &allocated_image->list; @@ -919,10 +917,9 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) goto err_ctrlr; resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); - if (resource == NULL) { - printk(KERN_WARNING "Unable to allocate resource structure\n"); + if (!resource) goto err_alloc; - } + resource->type = VME_DMA; resource->entry = &allocated_ctrlr->list; @@ -962,10 +959,9 @@ struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL); - if (dma_list == NULL) { - printk(KERN_ERR "Unable to allocate memory for new DMA list\n"); + if (!dma_list) return NULL; - } + INIT_LIST_HEAD(&dma_list->entries); dma_list->parent = ctrlr; mutex_init(&dma_list->mtx); @@ -991,16 +987,12 @@ struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) struct vme_dma_pattern *pattern_attr; attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); - if (attributes == NULL) { - printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); + if (!attributes) goto err_attr; - } pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); - if (pattern_attr == NULL) { - printk(KERN_ERR "Unable to allocate memory for pattern attributes\n"); + if (!pattern_attr) goto err_pat; - } attributes->type = VME_DMA_PATTERN; attributes->private = (void *)pattern_attr; @@ -1035,18 +1027,12 @@ struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) /* XXX Run some sanity checks here */ attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); - if (attributes == NULL) { - printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); + if (!attributes) goto err_attr; - } pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); - if (pci_attr == NULL) { - printk(KERN_ERR "Unable to allocate memory for PCI attributes\n"); + if (!pci_attr) goto err_pci; - } - - attributes->type = VME_DMA_PCI; attributes->private = (void *)pci_attr; @@ -1083,16 +1069,12 @@ struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, attributes = kmalloc( sizeof(struct vme_dma_attr), GFP_KERNEL); - if (attributes == NULL) { - printk(KERN_ERR "Unable to allocate memory for attributes structure\n"); + if (!attributes) goto err_attr; - } vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); - if (vme_attr == NULL) { - printk(KERN_ERR "Unable to allocate memory for VME attributes\n"); + if (!vme_attr) goto err_vme; - } attributes->type = VME_DMA_VME; attributes->private = (void *)vme_attr; @@ -1539,10 +1521,9 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev) goto err_lm; resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); - if (resource == NULL) { - printk(KERN_ERR "Unable to allocate resource structure\n"); + if (!resource) goto err_alloc; - } + resource->type = VME_LM; resource->entry = &allocated_lm->list; -- cgit v1.2.3-58-ga151 From 1ff0a19ce12c8292b732b564d25a9d3c5f819b1b Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 24 Aug 2017 21:52:00 +0200 Subject: vme: Improve 11 size determinations Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/vme.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index 53e87af8e0b8..1afddf5eafd4 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -336,7 +336,7 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, if (allocated_image == NULL) goto err_image; - resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); + resource = kmalloc(sizeof(*resource), GFP_KERNEL); if (!resource) goto err_alloc; @@ -540,7 +540,7 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, goto err_image; } - resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); + resource = kmalloc(sizeof(*resource), GFP_KERNEL); if (!resource) goto err_alloc; @@ -916,7 +916,7 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) if (allocated_ctrlr == NULL) goto err_ctrlr; - resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); + resource = kmalloc(sizeof(*resource), GFP_KERNEL); if (!resource) goto err_alloc; @@ -958,7 +958,7 @@ struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); - dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL); + dma_list = kmalloc(sizeof(*dma_list), GFP_KERNEL); if (!dma_list) return NULL; @@ -986,11 +986,11 @@ struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) struct vme_dma_attr *attributes; struct vme_dma_pattern *pattern_attr; - attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); + attributes = kmalloc(sizeof(*attributes), GFP_KERNEL); if (!attributes) goto err_attr; - pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); + pattern_attr = kmalloc(sizeof(*pattern_attr), GFP_KERNEL); if (!pattern_attr) goto err_pat; @@ -1026,11 +1026,11 @@ struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) /* XXX Run some sanity checks here */ - attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); + attributes = kmalloc(sizeof(*attributes), GFP_KERNEL); if (!attributes) goto err_attr; - pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); + pci_attr = kmalloc(sizeof(*pci_attr), GFP_KERNEL); if (!pci_attr) goto err_pci; @@ -1067,12 +1067,11 @@ struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, struct vme_dma_attr *attributes; struct vme_dma_vme *vme_attr; - attributes = kmalloc( - sizeof(struct vme_dma_attr), GFP_KERNEL); + attributes = kmalloc(sizeof(*attributes), GFP_KERNEL); if (!attributes) goto err_attr; - vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); + vme_attr = kmalloc(sizeof(*vme_attr), GFP_KERNEL); if (!vme_attr) goto err_vme; @@ -1520,7 +1519,7 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev) if (allocated_lm == NULL) goto err_lm; - resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL); + resource = kmalloc(sizeof(*resource), GFP_KERNEL); if (!resource) goto err_alloc; @@ -1869,7 +1868,7 @@ static int __vme_register_driver_bus(struct vme_driver *drv, struct vme_dev *tmp; for (i = 0; i < ndevs; i++) { - vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL); + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); if (!vdev) { err = -ENOMEM; goto err_devalloc; -- cgit v1.2.3-58-ga151 From a384b2cc13f6596a05069077bc3bc2c0cdd90156 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 24 Aug 2017 22:04:45 +0200 Subject: vme: Move an assignment in vme_new_dma_list() Assign a pointer to a data structure member without using an intermediate local variable. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/vme.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index 1afddf5eafd4..d890410e472d 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -948,7 +948,6 @@ EXPORT_SYMBOL(vme_dma_request); */ struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) { - struct vme_dma_resource *ctrlr; struct vme_dma_list *dma_list; if (resource->type != VME_DMA) { @@ -956,14 +955,14 @@ struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) return NULL; } - ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); - dma_list = kmalloc(sizeof(*dma_list), GFP_KERNEL); if (!dma_list) return NULL; INIT_LIST_HEAD(&dma_list->entries); - dma_list->parent = ctrlr; + dma_list->parent = list_entry(resource->entry, + struct vme_dma_resource, + list); mutex_init(&dma_list->mtx); return dma_list; -- cgit v1.2.3-58-ga151 From 61282c04984e405d3c79300e6008c3f5d60c280a Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 24 Aug 2017 22:24:38 +0200 Subject: vme: Adjust 48 checks for null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written … Thus fix the affected source code places. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/vme.c | 101 ++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 53 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index d890410e472d..a2e36e6a0d84 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -92,23 +92,23 @@ void *vme_alloc_consistent(struct vme_resource *resource, size_t size, { struct vme_bridge *bridge; - if (resource == NULL) { + if (!resource) { printk(KERN_ERR "No resource\n"); return NULL; } bridge = find_bridge(resource); - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find bridge\n"); return NULL; } - if (bridge->parent == NULL) { + if (!bridge->parent) { printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); return NULL; } - if (bridge->alloc_consistent == NULL) { + if (!bridge->alloc_consistent) { printk(KERN_ERR "alloc_consistent not supported by bridge %s\n", bridge->name); return NULL; @@ -132,23 +132,23 @@ void vme_free_consistent(struct vme_resource *resource, size_t size, { struct vme_bridge *bridge; - if (resource == NULL) { + if (!resource) { printk(KERN_ERR "No resource\n"); return; } bridge = find_bridge(resource); - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find bridge\n"); return; } - if (bridge->parent == NULL) { + if (!bridge->parent) { printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name); return; } - if (bridge->free_consistent == NULL) { + if (!bridge->free_consistent) { printk(KERN_ERR "free_consistent not supported by bridge %s\n", bridge->name); return; @@ -303,7 +303,7 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, struct vme_resource *resource = NULL; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); goto err_bus; } @@ -313,7 +313,7 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, slave_image = list_entry(slave_pos, struct vme_slave_resource, list); - if (slave_image == NULL) { + if (!slave_image) { printk(KERN_ERR "Registered NULL Slave resource\n"); continue; } @@ -333,7 +333,7 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, } /* No free image */ - if (allocated_image == NULL) + if (!allocated_image) goto err_image; resource = kmalloc(sizeof(*resource), GFP_KERNEL); @@ -388,7 +388,7 @@ int vme_slave_set(struct vme_resource *resource, int enabled, image = list_entry(resource->entry, struct vme_slave_resource, list); - if (bridge->slave_set == NULL) { + if (!bridge->slave_set) { printk(KERN_ERR "Function not supported\n"); return -ENOSYS; } @@ -437,7 +437,7 @@ int vme_slave_get(struct vme_resource *resource, int *enabled, image = list_entry(resource->entry, struct vme_slave_resource, list); - if (bridge->slave_get == NULL) { + if (!bridge->slave_get) { printk(KERN_ERR "vme_slave_get not supported\n"); return -EINVAL; } @@ -464,7 +464,7 @@ void vme_slave_free(struct vme_resource *resource) slave_image = list_entry(resource->entry, struct vme_slave_resource, list); - if (slave_image == NULL) { + if (!slave_image) { printk(KERN_ERR "Can't find slave resource\n"); return; } @@ -504,7 +504,7 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, struct vme_resource *resource = NULL; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); goto err_bus; } @@ -514,7 +514,7 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, master_image = list_entry(master_pos, struct vme_master_resource, list); - if (master_image == NULL) { + if (!master_image) { printk(KERN_WARNING "Registered NULL master resource\n"); continue; } @@ -535,7 +535,7 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, } /* Check to see if we found a resource */ - if (allocated_image == NULL) { + if (!allocated_image) { printk(KERN_ERR "Can't find a suitable resource\n"); goto err_image; } @@ -592,7 +592,7 @@ int vme_master_set(struct vme_resource *resource, int enabled, image = list_entry(resource->entry, struct vme_master_resource, list); - if (bridge->master_set == NULL) { + if (!bridge->master_set) { printk(KERN_WARNING "vme_master_set not supported\n"); return -EINVAL; } @@ -642,7 +642,7 @@ int vme_master_get(struct vme_resource *resource, int *enabled, image = list_entry(resource->entry, struct vme_master_resource, list); - if (bridge->master_get == NULL) { + if (!bridge->master_get) { printk(KERN_WARNING "%s not supported\n", __func__); return -EINVAL; } @@ -674,7 +674,7 @@ ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count, struct vme_master_resource *image; size_t length; - if (bridge->master_read == NULL) { + if (!bridge->master_read) { printk(KERN_WARNING "Reading from resource not supported\n"); return -EINVAL; } @@ -723,7 +723,7 @@ ssize_t vme_master_write(struct vme_resource *resource, void *buf, struct vme_master_resource *image; size_t length; - if (bridge->master_write == NULL) { + if (!bridge->master_write) { printk(KERN_WARNING "Writing to resource not supported\n"); return -EINVAL; } @@ -774,7 +774,7 @@ unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask, struct vme_bridge *bridge = find_bridge(resource); struct vme_master_resource *image; - if (bridge->master_rmw == NULL) { + if (!bridge->master_rmw) { printk(KERN_WARNING "Writing to resource not supported\n"); return -EINVAL; } @@ -844,7 +844,7 @@ void vme_master_free(struct vme_resource *resource) master_image = list_entry(resource->entry, struct vme_master_resource, list); - if (master_image == NULL) { + if (!master_image) { printk(KERN_ERR "Can't find master resource\n"); return; } @@ -884,7 +884,7 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) printk(KERN_ERR "No VME resource Attribute tests done\n"); bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); goto err_bus; } @@ -893,8 +893,7 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) list_for_each(dma_pos, &bridge->dma_resources) { dma_ctrlr = list_entry(dma_pos, struct vme_dma_resource, list); - - if (dma_ctrlr == NULL) { + if (!dma_ctrlr) { printk(KERN_ERR "Registered NULL DMA resource\n"); continue; } @@ -913,7 +912,7 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) } /* Check to see if we found a resource */ - if (allocated_ctrlr == NULL) + if (!allocated_ctrlr) goto err_ctrlr; resource = kmalloc(sizeof(*resource), GFP_KERNEL); @@ -1128,7 +1127,7 @@ int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, struct vme_bridge *bridge = list->parent->parent; int retval; - if (bridge->dma_list_add == NULL) { + if (!bridge->dma_list_add) { printk(KERN_WARNING "Link List DMA generation not supported\n"); return -EINVAL; } @@ -1161,7 +1160,7 @@ int vme_dma_list_exec(struct vme_dma_list *list) struct vme_bridge *bridge = list->parent->parent; int retval; - if (bridge->dma_list_exec == NULL) { + if (!bridge->dma_list_exec) { printk(KERN_ERR "Link List DMA execution not supported\n"); return -EINVAL; } @@ -1190,7 +1189,7 @@ int vme_dma_list_free(struct vme_dma_list *list) struct vme_bridge *bridge = list->parent->parent; int retval; - if (bridge->dma_list_empty == NULL) { + if (!bridge->dma_list_empty) { printk(KERN_WARNING "Emptying of Link Lists not supported\n"); return -EINVAL; } @@ -1322,8 +1321,7 @@ void vme_irq_handler(struct vme_bridge *bridge, int level, int statid) call = bridge->irq[level - 1].callback[statid].func; priv_data = bridge->irq[level - 1].callback[statid].priv_data; - - if (call != NULL) + if (call) call(level, statid, priv_data); else printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n", @@ -1354,7 +1352,7 @@ int vme_irq_request(struct vme_dev *vdev, int level, int statid, struct vme_bridge *bridge; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); return -EINVAL; } @@ -1364,7 +1362,7 @@ int vme_irq_request(struct vme_dev *vdev, int level, int statid, return -EINVAL; } - if (bridge->irq_set == NULL) { + if (!bridge->irq_set) { printk(KERN_ERR "Configuring interrupts not supported\n"); return -EINVAL; } @@ -1403,7 +1401,7 @@ void vme_irq_free(struct vme_dev *vdev, int level, int statid) struct vme_bridge *bridge; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); return; } @@ -1413,7 +1411,7 @@ void vme_irq_free(struct vme_dev *vdev, int level, int statid) return; } - if (bridge->irq_set == NULL) { + if (!bridge->irq_set) { printk(KERN_ERR "Configuring interrupts not supported\n"); return; } @@ -1450,7 +1448,7 @@ int vme_irq_generate(struct vme_dev *vdev, int level, int statid) struct vme_bridge *bridge; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); return -EINVAL; } @@ -1460,7 +1458,7 @@ int vme_irq_generate(struct vme_dev *vdev, int level, int statid) return -EINVAL; } - if (bridge->irq_generate == NULL) { + if (!bridge->irq_generate) { printk(KERN_WARNING "Interrupt generation not supported\n"); return -EINVAL; } @@ -1488,7 +1486,7 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev) struct vme_resource *resource = NULL; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); goto err_bus; } @@ -1497,8 +1495,7 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev) list_for_each(lm_pos, &bridge->lm_resources) { lm = list_entry(lm_pos, struct vme_lm_resource, list); - - if (lm == NULL) { + if (!lm) { printk(KERN_ERR "Registered NULL Location Monitor resource\n"); continue; } @@ -1515,7 +1512,7 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev) } /* Check to see if we found a resource */ - if (allocated_lm == NULL) + if (!allocated_lm) goto err_lm; resource = kmalloc(sizeof(*resource), GFP_KERNEL); @@ -1591,7 +1588,7 @@ int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base, lm = list_entry(resource->entry, struct vme_lm_resource, list); - if (bridge->lm_set == NULL) { + if (!bridge->lm_set) { printk(KERN_ERR "vme_lm_set not supported\n"); return -EINVAL; } @@ -1627,7 +1624,7 @@ int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base, lm = list_entry(resource->entry, struct vme_lm_resource, list); - if (bridge->lm_get == NULL) { + if (!bridge->lm_get) { printk(KERN_ERR "vme_lm_get not supported\n"); return -EINVAL; } @@ -1664,7 +1661,7 @@ int vme_lm_attach(struct vme_resource *resource, int monitor, lm = list_entry(resource->entry, struct vme_lm_resource, list); - if (bridge->lm_attach == NULL) { + if (!bridge->lm_attach) { printk(KERN_ERR "vme_lm_attach not supported\n"); return -EINVAL; } @@ -1697,7 +1694,7 @@ int vme_lm_detach(struct vme_resource *resource, int monitor) lm = list_entry(resource->entry, struct vme_lm_resource, list); - if (bridge->lm_detach == NULL) { + if (!bridge->lm_detach) { printk(KERN_ERR "vme_lm_detach not supported\n"); return -EINVAL; } @@ -1759,12 +1756,12 @@ int vme_slot_num(struct vme_dev *vdev) struct vme_bridge *bridge; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { printk(KERN_ERR "Can't find VME bus\n"); return -EINVAL; } - if (bridge->slot_get == NULL) { + if (!bridge->slot_get) { printk(KERN_WARNING "vme_slot_num not supported\n"); return -EINVAL; } @@ -1787,7 +1784,7 @@ int vme_bus_num(struct vme_dev *vdev) struct vme_bridge *bridge; bridge = vdev->bridge; - if (bridge == NULL) { + if (!bridge) { pr_err("Can't find VME bus\n"); return -EINVAL; } @@ -2004,8 +2001,7 @@ static int vme_bus_probe(struct device *dev) struct vme_dev *vdev = dev_to_vme_dev(dev); driver = dev->platform_data; - - if (driver->probe != NULL) + if (driver->probe) retval = driver->probe(vdev); return retval; @@ -2018,8 +2014,7 @@ static int vme_bus_remove(struct device *dev) struct vme_dev *vdev = dev_to_vme_dev(dev); driver = dev->platform_data; - - if (driver->remove != NULL) + if (driver->remove) retval = driver->remove(vdev); return retval; -- cgit v1.2.3-58-ga151 From 8af70cd9d6dec3fb968613a8d5318039ac5497b1 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 24 Aug 2017 22:32:14 +0200 Subject: vme: Return directly in two functions Return directly without using an intermediate local variable in these functions. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/vme.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index a2e36e6a0d84..986799d64993 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -1996,28 +1996,26 @@ static int vme_bus_match(struct device *dev, struct device_driver *drv) static int vme_bus_probe(struct device *dev) { - int retval = -ENODEV; struct vme_driver *driver; struct vme_dev *vdev = dev_to_vme_dev(dev); driver = dev->platform_data; if (driver->probe) - retval = driver->probe(vdev); + return driver->probe(vdev); - return retval; + return -ENODEV; } static int vme_bus_remove(struct device *dev) { - int retval = -ENODEV; struct vme_driver *driver; struct vme_dev *vdev = dev_to_vme_dev(dev); driver = dev->platform_data; if (driver->remove) - retval = driver->remove(vdev); + return driver->remove(vdev); - return retval; + return -ENODEV; } struct bus_type vme_bus_type = { -- cgit v1.2.3-58-ga151 From ef544fbc53badd3ae1c85980211bd39419c4082a Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 09:31:46 +0200 Subject: vme: fake: Delete an error message for a failed memory allocation in fake_init() Omit an extra message for a memory allocation failure in this function. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_fake.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_fake.c b/drivers/vme/bridges/vme_fake.c index 30b3acc93833..6ceea5e9fd8b 100644 --- a/drivers/vme/bridges/vme_fake.c +++ b/drivers/vme/bridges/vme_fake.c @@ -1156,7 +1156,6 @@ static int __init fake_init(void) INIT_LIST_HEAD(&fake_bridge->lm_resources); lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); if (lm == NULL) { - pr_err("Failed to allocate memory for location monitor resource structure\n"); retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 246740656a37495c7a0b87c7dcfbb9b5d9bae9fd Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 09:46:13 +0200 Subject: vme: fake: Improve five size determinations in fake_init() Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_fake.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_fake.c b/drivers/vme/bridges/vme_fake.c index 6ceea5e9fd8b..39f84df44557 100644 --- a/drivers/vme/bridges/vme_fake.c +++ b/drivers/vme/bridges/vme_fake.c @@ -1075,13 +1075,13 @@ static int __init fake_init(void) /* If we want to support more than one bridge at some point, we need to * dynamically allocate this so we get one per device. */ - fake_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); + fake_bridge = kzalloc(sizeof(*fake_bridge), GFP_KERNEL); if (fake_bridge == NULL) { retval = -ENOMEM; goto err_struct; } - fake_device = kzalloc(sizeof(struct fake_driver), GFP_KERNEL); + fake_device = kzalloc(sizeof(*fake_device), GFP_KERNEL); if (fake_device == NULL) { retval = -ENOMEM; goto err_driver; @@ -1104,8 +1104,7 @@ static int __init fake_init(void) /* Add master windows to list */ INIT_LIST_HEAD(&fake_bridge->master_resources); for (i = 0; i < FAKE_MAX_MASTER; i++) { - master_image = kmalloc(sizeof(struct vme_master_resource), - GFP_KERNEL); + master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); if (master_image == NULL) { retval = -ENOMEM; goto err_master; @@ -1131,8 +1130,7 @@ static int __init fake_init(void) /* Add slave windows to list */ INIT_LIST_HEAD(&fake_bridge->slave_resources); for (i = 0; i < FAKE_MAX_SLAVE; i++) { - slave_image = kmalloc(sizeof(struct vme_slave_resource), - GFP_KERNEL); + slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); if (slave_image == NULL) { retval = -ENOMEM; goto err_slave; @@ -1154,7 +1152,7 @@ static int __init fake_init(void) /* Add location monitor to list */ INIT_LIST_HEAD(&fake_bridge->lm_resources); - lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); + lm = kmalloc(sizeof(*lm), GFP_KERNEL); if (lm == NULL) { retval = -ENOMEM; goto err_lm; -- cgit v1.2.3-58-ga151 From 2444d37fb01c05adb04cb3297097e02f81024616 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 10:01:16 +0200 Subject: vme: fake: Adjust 11 checks for null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written … Thus fix the affected source code places. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_fake.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_fake.c b/drivers/vme/bridges/vme_fake.c index 39f84df44557..7d83691047f4 100644 --- a/drivers/vme/bridges/vme_fake.c +++ b/drivers/vme/bridges/vme_fake.c @@ -409,7 +409,7 @@ static void fake_lm_check(struct fake_driver *bridge, unsigned long long addr, /* Each location monitor covers 8 bytes */ if (((lm_base + (8 * i)) <= addr) && ((lm_base + (8 * i) + 8) > addr)) { - if (bridge->lm_callback[i] != NULL) + if (bridge->lm_callback[i]) bridge->lm_callback[i]( bridge->lm_data[i]); } @@ -866,7 +866,7 @@ static int fake_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, /* If we already have a callback attached, we can't move it! */ for (i = 0; i < lm->monitors; i++) { - if (bridge->lm_callback[i] != NULL) { + if (bridge->lm_callback[i]) { mutex_unlock(&lm->mtx); pr_err("Location monitor callback attached, can't reset\n"); return -EBUSY; @@ -940,7 +940,7 @@ static int fake_lm_attach(struct vme_lm_resource *lm, int monitor, } /* Check that a callback isn't already attached */ - if (bridge->lm_callback[monitor] != NULL) { + if (bridge->lm_callback[monitor]) { mutex_unlock(&lm->mtx); pr_err("Existing callback attached\n"); return -EBUSY; @@ -978,7 +978,7 @@ static int fake_lm_detach(struct vme_lm_resource *lm, int monitor) /* If all location monitors disabled, disable global Location Monitor */ tmp = 0; for (i = 0; i < lm->monitors; i++) { - if (bridge->lm_callback[i] != NULL) + if (bridge->lm_callback[i]) tmp = 1; } @@ -1003,7 +1003,7 @@ static void *fake_alloc_consistent(struct device *parent, size_t size, { void *alloc = kmalloc(size, GFP_KERNEL); - if (alloc != NULL) + if (alloc) *dma = fake_ptr_to_pci(alloc); return alloc; @@ -1039,7 +1039,7 @@ static int fake_crcsr_init(struct vme_bridge *fake_bridge) /* Allocate mem for CR/CSR image */ bridge->crcsr_kernel = kzalloc(VME_CRCSR_BUF_SIZE, GFP_KERNEL); bridge->crcsr_bus = fake_ptr_to_pci(bridge->crcsr_kernel); - if (bridge->crcsr_kernel == NULL) + if (!bridge->crcsr_kernel) return -ENOMEM; vstat = fake_slot_get(fake_bridge); @@ -1076,13 +1076,13 @@ static int __init fake_init(void) * dynamically allocate this so we get one per device. */ fake_bridge = kzalloc(sizeof(*fake_bridge), GFP_KERNEL); - if (fake_bridge == NULL) { + if (!fake_bridge) { retval = -ENOMEM; goto err_struct; } fake_device = kzalloc(sizeof(*fake_device), GFP_KERNEL); - if (fake_device == NULL) { + if (!fake_device) { retval = -ENOMEM; goto err_driver; } @@ -1105,7 +1105,7 @@ static int __init fake_init(void) INIT_LIST_HEAD(&fake_bridge->master_resources); for (i = 0; i < FAKE_MAX_MASTER; i++) { master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); - if (master_image == NULL) { + if (!master_image) { retval = -ENOMEM; goto err_master; } @@ -1131,7 +1131,7 @@ static int __init fake_init(void) INIT_LIST_HEAD(&fake_bridge->slave_resources); for (i = 0; i < FAKE_MAX_SLAVE; i++) { slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); - if (slave_image == NULL) { + if (!slave_image) { retval = -ENOMEM; goto err_slave; } @@ -1153,7 +1153,7 @@ static int __init fake_init(void) /* Add location monitor to list */ INIT_LIST_HEAD(&fake_bridge->lm_resources); lm = kmalloc(sizeof(*lm), GFP_KERNEL); - if (lm == NULL) { + if (!lm) { retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 85fd4939e53873839df8e78da917c79c5074b183 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 10:20:03 +0200 Subject: vme: ca91cx42: Delete eight error messages for a failed memory allocation Omit extra messages for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_ca91cx42.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c index 7cc51223db1c..d25f997e8aeb 100644 --- a/drivers/vme/bridges/vme_ca91cx42.c +++ b/drivers/vme/bridges/vme_ca91cx42.c @@ -535,8 +535,6 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image, if (image->bus_resource.name == NULL) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); if (image->bus_resource.name == NULL) { - dev_err(ca91cx42_bridge->parent, "Unable to allocate " - "memory for resource name\n"); retval = -ENOMEM; goto err_name; } @@ -1038,8 +1036,6 @@ static int ca91cx42_dma_list_add(struct vme_dma_list *list, /* XXX descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(struct ca91cx42_dma_entry), GFP_KERNEL); if (entry == NULL) { - dev_err(dev, "Failed to allocate memory for dma resource " - "structure\n"); retval = -ENOMEM; goto err_mem; } @@ -1621,8 +1617,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) ca91cx42_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); if (ca91cx42_bridge == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_struct; } @@ -1631,8 +1625,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) ca91cx42_device = kzalloc(sizeof(struct ca91cx42_driver), GFP_KERNEL); if (ca91cx42_device == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_driver; } @@ -1691,8 +1683,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) master_image = kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); if (master_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "master resource structure\n"); retval = -ENOMEM; goto err_master; } @@ -1717,8 +1707,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) slave_image = kmalloc(sizeof(struct vme_slave_resource), GFP_KERNEL); if (slave_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "slave resource structure\n"); retval = -ENOMEM; goto err_slave; } @@ -1744,8 +1732,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), GFP_KERNEL); if (dma_ctrlr == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "dma resource structure\n"); retval = -ENOMEM; goto err_dma; } @@ -1764,8 +1750,6 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); if (lm == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "location monitor resource structure\n"); retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 3d9b1e53343651e514644f2a6d4ce00b362f4033 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 10:56:41 +0200 Subject: vme: ca91cx42: Improve 12 size determinations Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_ca91cx42.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c index d25f997e8aeb..61990c7f4543 100644 --- a/drivers/vme/bridges/vme_ca91cx42.c +++ b/drivers/vme/bridges/vme_ca91cx42.c @@ -529,7 +529,7 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image, image->kern_base = NULL; kfree(image->bus_resource.name); release_resource(&image->bus_resource); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } if (image->bus_resource.name == NULL) { @@ -572,7 +572,7 @@ err_remap: release_resource(&image->bus_resource); err_resource: kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); err_name: return retval; } @@ -586,7 +586,7 @@ static void ca91cx42_free_resource(struct vme_master_resource *image) image->kern_base = NULL; release_resource(&image->bus_resource); kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } @@ -1034,7 +1034,7 @@ static int ca91cx42_dma_list_add(struct vme_dma_list *list, dev = list->parent->parent->parent; /* XXX descriptor must be aligned on 64-bit boundaries */ - entry = kmalloc(sizeof(struct ca91cx42_dma_entry), GFP_KERNEL); + entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (entry == NULL) { retval = -ENOMEM; goto err_mem; @@ -1048,7 +1048,7 @@ static int ca91cx42_dma_list_add(struct vme_dma_list *list, goto err_align; } - memset(&entry->descriptor, 0, sizeof(struct ca91cx42_dma_descriptor)); + memset(&entry->descriptor, 0, sizeof(entry->descriptor)); if (dest->type == VME_DMA_VME) { entry->descriptor.dctl |= CA91CX42_DCTL_L2V; @@ -1614,16 +1614,14 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* We want to support more than one of each bridge so we need to * dynamically allocate the bridge structure */ - ca91cx42_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); - + ca91cx42_bridge = kzalloc(sizeof(*ca91cx42_bridge), GFP_KERNEL); if (ca91cx42_bridge == NULL) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(ca91cx42_bridge); - ca91cx42_device = kzalloc(sizeof(struct ca91cx42_driver), GFP_KERNEL); - + ca91cx42_device = kzalloc(sizeof(*ca91cx42_device), GFP_KERNEL); if (ca91cx42_device == NULL) { retval = -ENOMEM; goto err_driver; @@ -1680,8 +1678,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add master windows to list */ for (i = 0; i < CA91C142_MAX_MASTER; i++) { - master_image = kmalloc(sizeof(struct vme_master_resource), - GFP_KERNEL); + master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); if (master_image == NULL) { retval = -ENOMEM; goto err_master; @@ -1696,7 +1693,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) VME_SUPER | VME_USER | VME_PROG | VME_DATA; master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64; memset(&master_image->bus_resource, 0, - sizeof(struct resource)); + sizeof(master_image->bus_resource)); master_image->kern_base = NULL; list_add_tail(&master_image->list, &ca91cx42_bridge->master_resources); @@ -1704,8 +1701,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < CA91C142_MAX_SLAVE; i++) { - slave_image = kmalloc(sizeof(struct vme_slave_resource), - GFP_KERNEL); + slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); if (slave_image == NULL) { retval = -ENOMEM; goto err_slave; @@ -1729,8 +1725,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < CA91C142_MAX_DMA; i++) { - dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), - GFP_KERNEL); + dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); if (dma_ctrlr == NULL) { retval = -ENOMEM; goto err_dma; @@ -1748,7 +1743,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) } /* Add location monitor to list */ - lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); + lm = kmalloc(sizeof(*lm), GFP_KERNEL); if (lm == NULL) { retval = -ENOMEM; goto err_lm; -- cgit v1.2.3-58-ga151 From 8d97931740cff8f4eea62f5690e470444905db60 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 11:01:29 +0200 Subject: vme: ca91cx42: Adjust 14 checks for null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written … Thus fix the affected source code places. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_ca91cx42.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c index 61990c7f4543..5dd284008630 100644 --- a/drivers/vme/bridges/vme_ca91cx42.c +++ b/drivers/vme/bridges/vme_ca91cx42.c @@ -511,7 +511,7 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image, ca91cx42_bridge = image->parent; /* Find pci_dev container of dev */ - if (ca91cx42_bridge->parent == NULL) { + if (!ca91cx42_bridge->parent) { dev_err(ca91cx42_bridge->parent, "Dev entry NULL\n"); return -EINVAL; } @@ -532,9 +532,9 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image, memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { retval = -ENOMEM; goto err_name; } @@ -560,7 +560,7 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image, image->kern_base = ioremap_nocache( image->bus_resource.start, size); - if (image->kern_base == NULL) { + if (!image->kern_base) { dev_err(ca91cx42_bridge->parent, "Failed to remap resource\n"); retval = -ENOMEM; goto err_remap; @@ -1035,7 +1035,7 @@ static int ca91cx42_dma_list_add(struct vme_dma_list *list, /* XXX descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(*entry), GFP_KERNEL); - if (entry == NULL) { + if (!entry) { retval = -ENOMEM; goto err_mem; } @@ -1319,7 +1319,7 @@ static int ca91cx42_lm_set(struct vme_lm_resource *lm, /* If we already have a callback attached, we can't move it! */ for (i = 0; i < lm->monitors; i++) { - if (bridge->lm_callback[i] != NULL) { + if (bridge->lm_callback[i]) { mutex_unlock(&lm->mtx); dev_err(dev, "Location monitor callback attached, " "can't reset\n"); @@ -1428,7 +1428,7 @@ static int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor, } /* Check that a callback isn't already attached */ - if (bridge->lm_callback[monitor] != NULL) { + if (bridge->lm_callback[monitor]) { mutex_unlock(&lm->mtx); dev_err(dev, "Existing callback attached\n"); return -EBUSY; @@ -1563,7 +1563,7 @@ static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge, /* Allocate mem for CR/CSR image */ bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE, &bridge->crcsr_bus); - if (bridge->crcsr_kernel == NULL) { + if (!bridge->crcsr_kernel) { dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR " "image\n"); return -ENOMEM; @@ -1615,14 +1615,14 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) * dynamically allocate the bridge structure */ ca91cx42_bridge = kzalloc(sizeof(*ca91cx42_bridge), GFP_KERNEL); - if (ca91cx42_bridge == NULL) { + if (!ca91cx42_bridge) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(ca91cx42_bridge); ca91cx42_device = kzalloc(sizeof(*ca91cx42_device), GFP_KERNEL); - if (ca91cx42_device == NULL) { + if (!ca91cx42_device) { retval = -ENOMEM; goto err_driver; } @@ -1679,7 +1679,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add master windows to list */ for (i = 0; i < CA91C142_MAX_MASTER; i++) { master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); - if (master_image == NULL) { + if (!master_image) { retval = -ENOMEM; goto err_master; } @@ -1702,7 +1702,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < CA91C142_MAX_SLAVE; i++) { slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); - if (slave_image == NULL) { + if (!slave_image) { retval = -ENOMEM; goto err_slave; } @@ -1726,7 +1726,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < CA91C142_MAX_DMA; i++) { dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); - if (dma_ctrlr == NULL) { + if (!dma_ctrlr) { retval = -ENOMEM; goto err_dma; } @@ -1744,7 +1744,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(*lm), GFP_KERNEL); - if (lm == NULL) { + if (!lm) { retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 97660957fb5318d76a680a1b6cfb7b998bfa3723 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 11:10:07 +0200 Subject: vme: tsi148: Delete nine error messages for a failed memory allocation Omit extra messages for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index fc1b634b969a..fb91fddc6312 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -751,8 +751,6 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, if (image->bus_resource.name == NULL) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); if (image->bus_resource.name == NULL) { - dev_err(tsi148_bridge->parent, "Unable to allocate " - "memory for resource name\n"); retval = -ENOMEM; goto err_name; } @@ -1643,8 +1641,6 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(struct tsi148_dma_entry), GFP_KERNEL); if (entry == NULL) { - dev_err(tsi148_bridge->parent, "Failed to allocate memory for " - "dma resource structure\n"); retval = -ENOMEM; goto err_mem; } @@ -2296,8 +2292,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) */ tsi148_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); if (tsi148_bridge == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_struct; } @@ -2305,8 +2299,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device = kzalloc(sizeof(struct tsi148_driver), GFP_KERNEL); if (tsi148_device == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_driver; } @@ -2373,8 +2365,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image = kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); if (tsi148_device->flush_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "flush resource structure\n"); retval = -ENOMEM; goto err_master; } @@ -2392,8 +2382,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) master_image = kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); if (master_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "master resource structure\n"); retval = -ENOMEM; goto err_master; } @@ -2421,8 +2409,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) slave_image = kmalloc(sizeof(struct vme_slave_resource), GFP_KERNEL); if (slave_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "slave resource structure\n"); retval = -ENOMEM; goto err_slave; } @@ -2445,8 +2431,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), GFP_KERNEL); if (dma_ctrlr == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "dma resource structure\n"); retval = -ENOMEM; goto err_dma; } @@ -2467,8 +2451,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); if (lm == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "location monitor resource structure\n"); retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 6d011dd876cb825b2e1213daaabda07e1151fc6a Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 11:55:03 +0200 Subject: vme: tsi148: Improve 17 size determinations Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring [martyn@welchs.me.uk: Correct long line] Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index fb91fddc6312..946f62597360 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -741,7 +741,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, image->kern_base = NULL; kfree(image->bus_resource.name); release_resource(&image->bus_resource); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } /* Exit here if size is zero */ @@ -788,7 +788,7 @@ err_remap: release_resource(&image->bus_resource); err_resource: kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); err_name: return retval; } @@ -802,7 +802,7 @@ static void tsi148_free_resource(struct vme_master_resource *image) image->kern_base = NULL; release_resource(&image->bus_resource); kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } /* @@ -1639,7 +1639,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, tsi148_bridge = list->parent->parent; /* Descriptor must be aligned on 64-bit boundaries */ - entry = kmalloc(sizeof(struct tsi148_dma_entry), GFP_KERNEL); + entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (entry == NULL) { retval = -ENOMEM; goto err_mem; @@ -1657,7 +1657,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Given we are going to fill out the structure, we probably don't * need to zero it, but better safe than sorry for now. */ - memset(&entry->descriptor, 0, sizeof(struct tsi148_dma_descriptor)); + memset(&entry->descriptor, 0, sizeof(entry->descriptor)); /* Fill out source part */ switch (src->type) { @@ -1752,8 +1752,9 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, list_add_tail(&entry->list, &list->entries); entry->dma_handle = dma_map_single(tsi148_bridge->parent, - &entry->descriptor, - sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE); + &entry->descriptor, + sizeof(entry->descriptor), + DMA_TO_DEVICE); if (dma_mapping_error(tsi148_bridge->parent, entry->dma_handle)) { dev_err(tsi148_bridge->parent, "DMA mapping error\n"); retval = -EINVAL; @@ -2290,14 +2291,14 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* If we want to support more than one of each bridge, we need to * dynamically generate this so we get one per device */ - tsi148_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); + tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL); if (tsi148_bridge == NULL) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(tsi148_bridge); - tsi148_device = kzalloc(sizeof(struct tsi148_driver), GFP_KERNEL); + tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL); if (tsi148_device == NULL) { retval = -ENOMEM; goto err_driver; @@ -2363,7 +2364,8 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) master_num--; tsi148_device->flush_image = - kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); + kmalloc(sizeof(*tsi148_device->flush_image), + GFP_KERNEL); if (tsi148_device->flush_image == NULL) { retval = -ENOMEM; goto err_master; @@ -2373,14 +2375,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image->locked = 1; tsi148_device->flush_image->number = master_num; memset(&tsi148_device->flush_image->bus_resource, 0, - sizeof(struct resource)); + sizeof(tsi148_device->flush_image->bus_resource)); tsi148_device->flush_image->kern_base = NULL; } /* Add master windows to list */ for (i = 0; i < master_num; i++) { - master_image = kmalloc(sizeof(struct vme_master_resource), - GFP_KERNEL); + master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); if (master_image == NULL) { retval = -ENOMEM; goto err_master; @@ -2398,7 +2399,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) VME_PROG | VME_DATA; master_image->width_attr = VME_D16 | VME_D32; memset(&master_image->bus_resource, 0, - sizeof(struct resource)); + sizeof(master_image->bus_resource)); master_image->kern_base = NULL; list_add_tail(&master_image->list, &tsi148_bridge->master_resources); @@ -2406,8 +2407,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < TSI148_MAX_SLAVE; i++) { - slave_image = kmalloc(sizeof(struct vme_slave_resource), - GFP_KERNEL); + slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); if (slave_image == NULL) { retval = -ENOMEM; goto err_slave; @@ -2428,8 +2428,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < TSI148_MAX_DMA; i++) { - dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), - GFP_KERNEL); + dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); if (dma_ctrlr == NULL) { retval = -ENOMEM; goto err_dma; @@ -2449,7 +2448,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) } /* Add location monitor to list */ - lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); + lm = kmalloc(sizeof(*lm), GFP_KERNEL); if (lm == NULL) { retval = -ENOMEM; goto err_lm; -- cgit v1.2.3-58-ga151 From a75dc630086a6b83d780a7b27d03c4c0abdf0807 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 12:00:17 +0200 Subject: vme: tsi148: Adjust 14 checks for null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written … Thus fix the affected source code places. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index 946f62597360..647d231d4422 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -748,9 +748,9 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, if (size == 0) return 0; - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { retval = -ENOMEM; goto err_name; } @@ -776,7 +776,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, image->kern_base = ioremap_nocache( image->bus_resource.start, size); - if (image->kern_base == NULL) { + if (!image->kern_base) { dev_err(tsi148_bridge->parent, "Failed to remap resource\n"); retval = -ENOMEM; goto err_remap; @@ -1640,7 +1640,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(*entry), GFP_KERNEL); - if (entry == NULL) { + if (!entry) { retval = -ENOMEM; goto err_mem; } @@ -1943,7 +1943,7 @@ static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, /* If we already have a callback attached, we can't move it! */ for (i = 0; i < lm->monitors; i++) { - if (bridge->lm_callback[i] != NULL) { + if (bridge->lm_callback[i]) { mutex_unlock(&lm->mtx); dev_err(tsi148_bridge->parent, "Location monitor " "callback attached, can't reset\n"); @@ -2068,7 +2068,7 @@ static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor, } /* Check that a callback isn't already attached */ - if (bridge->lm_callback[monitor] != NULL) { + if (bridge->lm_callback[monitor]) { mutex_unlock(&lm->mtx); dev_err(tsi148_bridge->parent, "Existing callback attached\n"); return -EBUSY; @@ -2205,7 +2205,7 @@ static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge, /* Allocate mem for CR/CSR image */ bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE, &bridge->crcsr_bus); - if (bridge->crcsr_kernel == NULL) { + if (!bridge->crcsr_kernel) { dev_err(tsi148_bridge->parent, "Failed to allocate memory for " "CR/CSR image\n"); return -ENOMEM; @@ -2292,14 +2292,14 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) * dynamically generate this so we get one per device */ tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL); - if (tsi148_bridge == NULL) { + if (!tsi148_bridge) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(tsi148_bridge); tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL); - if (tsi148_device == NULL) { + if (!tsi148_device) { retval = -ENOMEM; goto err_driver; } @@ -2366,7 +2366,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image = kmalloc(sizeof(*tsi148_device->flush_image), GFP_KERNEL); - if (tsi148_device->flush_image == NULL) { + if (!tsi148_device->flush_image) { retval = -ENOMEM; goto err_master; } @@ -2382,7 +2382,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add master windows to list */ for (i = 0; i < master_num; i++) { master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); - if (master_image == NULL) { + if (!master_image) { retval = -ENOMEM; goto err_master; } @@ -2408,7 +2408,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < TSI148_MAX_SLAVE; i++) { slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); - if (slave_image == NULL) { + if (!slave_image) { retval = -ENOMEM; goto err_slave; } @@ -2429,7 +2429,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < TSI148_MAX_DMA; i++) { dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); - if (dma_ctrlr == NULL) { + if (!dma_ctrlr) { retval = -ENOMEM; goto err_dma; } @@ -2449,7 +2449,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(*lm), GFP_KERNEL); - if (lm == NULL) { + if (!lm) { retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3-58-ga151 From 0bbb194c0c33c251ac3d33f46c8fd045d82350e5 Mon Sep 17 00:00:00 2001 From: Suzuki K Poulose Date: Tue, 10 Oct 2017 14:32:12 -0600 Subject: coresight: Extend the PIDR mask to cover relevant bits in PIDR2 As per coresight standards, PIDR2 register has the following format : [2-0] - JEP106_bits6to4 [3] - JEDEC, designer ID is specified by JEDEC. However some of the drivers only use mask of 0x3 for the PIDR2 leaving bits [3-2] unchecked, which could potentially match the component for a different device altogether. This patch fixes the mask and the corresponding id bits for the existing devices. Cc: Mathieu Poirier Cc: Linus Walleij Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier Signed-off-by: Greg Kroah-Hartman --- .../coresight/coresight-dynamic-replicator.c | 4 ++-- drivers/hwtracing/coresight/coresight-etb10.c | 4 ++-- drivers/hwtracing/coresight/coresight-etm3x.c | 24 +++++++++++----------- drivers/hwtracing/coresight/coresight-funnel.c | 4 ++-- drivers/hwtracing/coresight/coresight-stm.c | 8 ++++---- drivers/hwtracing/coresight/coresight-tmc.c | 4 ++-- drivers/hwtracing/coresight/coresight-tpiu.c | 4 ++-- 7 files changed, 26 insertions(+), 26 deletions(-) (limited to 'drivers') diff --git a/drivers/hwtracing/coresight/coresight-dynamic-replicator.c b/drivers/hwtracing/coresight/coresight-dynamic-replicator.c index accc2056f7c6..8f4357e2626c 100644 --- a/drivers/hwtracing/coresight/coresight-dynamic-replicator.c +++ b/drivers/hwtracing/coresight/coresight-dynamic-replicator.c @@ -199,8 +199,8 @@ static const struct dev_pm_ops replicator_dev_pm_ops = { static const struct amba_id replicator_ids[] = { { - .id = 0x0003b909, - .mask = 0x0003ffff, + .id = 0x000bb909, + .mask = 0x000fffff, }, { /* Coresight SoC-600 */ diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 56ecd7aff5eb..e03e58933141 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -748,8 +748,8 @@ static const struct dev_pm_ops etb_dev_pm_ops = { static const struct amba_id etb_ids[] = { { - .id = 0x0003b907, - .mask = 0x0003ffff, + .id = 0x000bb907, + .mask = 0x000fffff, }, { 0, 0}, }; diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c index e5b1ec57dbde..39f42fdd503d 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x.c +++ b/drivers/hwtracing/coresight/coresight-etm3x.c @@ -901,33 +901,33 @@ static const struct dev_pm_ops etm_dev_pm_ops = { static const struct amba_id etm_ids[] = { { /* ETM 3.3 */ - .id = 0x0003b921, - .mask = 0x0003ffff, + .id = 0x000bb921, + .mask = 0x000fffff, .data = "ETM 3.3", }, { /* ETM 3.5 - Cortex-A5 */ - .id = 0x0003b955, - .mask = 0x0003ffff, + .id = 0x000bb955, + .mask = 0x000fffff, .data = "ETM 3.5", }, { /* ETM 3.5 */ - .id = 0x0003b956, - .mask = 0x0003ffff, + .id = 0x000bb956, + .mask = 0x000fffff, .data = "ETM 3.5", }, { /* PTM 1.0 */ - .id = 0x0003b950, - .mask = 0x0003ffff, + .id = 0x000bb950, + .mask = 0x000fffff, .data = "PTM 1.0", }, { /* PTM 1.1 */ - .id = 0x0003b95f, - .mask = 0x0003ffff, + .id = 0x000bb95f, + .mask = 0x000fffff, .data = "PTM 1.1", }, { /* PTM 1.1 Qualcomm */ - .id = 0x0003006f, - .mask = 0x0003ffff, + .id = 0x000b006f, + .mask = 0x000fffff, .data = "PTM 1.1", }, { 0, 0}, diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c index 77642e0e955b..fd3c396717f6 100644 --- a/drivers/hwtracing/coresight/coresight-funnel.c +++ b/drivers/hwtracing/coresight/coresight-funnel.c @@ -248,8 +248,8 @@ static const struct dev_pm_ops funnel_dev_pm_ops = { static const struct amba_id funnel_ids[] = { { - .id = 0x0003b908, - .mask = 0x0003ffff, + .id = 0x000bb908, + .mask = 0x000fffff, }, { /* Coresight SoC-600 */ diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c index 92a780a6df1d..15e7ef3891f5 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -917,13 +917,13 @@ static const struct dev_pm_ops stm_dev_pm_ops = { static const struct amba_id stm_ids[] = { { - .id = 0x0003b962, - .mask = 0x0003ffff, + .id = 0x000bb962, + .mask = 0x000fffff, .data = "STM32", }, { - .id = 0x0003b963, - .mask = 0x0003ffff, + .id = 0x000bb963, + .mask = 0x000fffff, .data = "STM500", }, { 0, 0}, diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index 2ff4a66a3caa..0ea04f588de0 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -439,8 +439,8 @@ out: static const struct amba_id tmc_ids[] = { { - .id = 0x0003b961, - .mask = 0x0003ffff, + .id = 0x000bb961, + .mask = 0x000fffff, }, { /* Coresight SoC 600 TMC-ETR/ETS */ diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index d7a3e453016d..bef49a3a5ca7 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -194,8 +194,8 @@ static const struct dev_pm_ops tpiu_dev_pm_ops = { static const struct amba_id tpiu_ids[] = { { - .id = 0x0003b912, - .mask = 0x0003ffff, + .id = 0x000bb912, + .mask = 0x000fffff, }, { .id = 0x0004b912, -- cgit v1.2.3-58-ga151 From 9577924bb33bc76c7a54c6ebde345f8e4de31a4e Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Mon, 16 Oct 2017 16:28:26 -0700 Subject: char: pcmcia: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Harald Welte Cc: "David S. Miller" Cc: Jarod Wilson Cc: Stephen Hemminger Cc: Johannes Berg Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/char/pcmcia/cm4000_cs.c | 6 +++--- drivers/char/pcmcia/cm4040_cs.c | 7 +++---- drivers/char/pcmcia/synclink_cs.c | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index cd53771b9ae7..370e0a64ead1 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c @@ -659,9 +659,9 @@ static void terminate_monitor(struct cm4000_dev *dev) * is already doing that for you. */ -static void monitor_card(unsigned long p) +static void monitor_card(struct timer_list *t) { - struct cm4000_dev *dev = (struct cm4000_dev *) p; + struct cm4000_dev *dev = from_timer(dev, t, timer); unsigned int iobase = dev->p_dev->resource[0]->start; unsigned short s; struct ptsreq ptsreq; @@ -1374,7 +1374,7 @@ static void start_monitor(struct cm4000_dev *dev) DEBUGP(3, dev, "-> start_monitor\n"); if (!dev->monitor_running) { DEBUGP(5, dev, "create, init and add timer\n"); - setup_timer(&dev->timer, monitor_card, (unsigned long)dev); + timer_setup(&dev->timer, monitor_card, 0); dev->monitor_running = 1; mod_timer(&dev->timer, jiffies); } else diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index 382c864814d9..9a1aaf538758 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c @@ -104,9 +104,9 @@ static inline unsigned char xinb(unsigned short port) /* poll the device fifo status register. not to be confused with * the poll syscall. */ -static void cm4040_do_poll(unsigned long dummy) +static void cm4040_do_poll(struct timer_list *t) { - struct reader_dev *dev = (struct reader_dev *) dummy; + struct reader_dev *dev = from_timer(dev, t, poll_timer); unsigned int obs = xinb(dev->p_dev->resource[0]->start + REG_OFFSET_BUFFER_STATUS); @@ -465,7 +465,6 @@ static int cm4040_open(struct inode *inode, struct file *filp) link->open = 1; - dev->poll_timer.data = (unsigned long) dev; mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD); DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); @@ -585,7 +584,7 @@ static int reader_probe(struct pcmcia_device *link) init_waitqueue_head(&dev->poll_wait); init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->write_wait); - setup_timer(&dev->poll_timer, cm4040_do_poll, 0); + timer_setup(&dev->poll_timer, cm4040_do_poll, 0); ret = reader_config(link, i); if (ret) { diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 62be953e5fb0..aa502e9fb7fa 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -375,7 +375,7 @@ static void reset_device(MGSLPC_INFO *info); static void hdlc_mode(MGSLPC_INFO *info); static void async_mode(MGSLPC_INFO *info); -static void tx_timeout(unsigned long context); +static void tx_timeout(struct timer_list *t); static int carrier_raised(struct tty_port *port); static void dtr_rts(struct tty_port *port, int onoff); @@ -1289,7 +1289,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) memset(&info->icount, 0, sizeof(info->icount)); - setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info); + timer_setup(&info->tx_timer, tx_timeout, 0); /* Allocate and claim adapter resources */ retval = claim_resources(info); @@ -3846,9 +3846,9 @@ static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit) /* HDLC frame time out * update stats and do tx completion processing */ -static void tx_timeout(unsigned long context) +static void tx_timeout(struct timer_list *t) { - MGSLPC_INFO *info = (MGSLPC_INFO*)context; + MGSLPC_INFO *info = from_timer(info, t, tx_timer); unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) -- cgit v1.2.3-58-ga151 From 35c3f85f5ab9cf6e5f0fd268485829a1122f7546 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Mon, 16 Oct 2017 16:27:53 -0700 Subject: pcmcia: m32r: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Andrew Morton Cc: Sudip Mukherjee Cc: linux-pcmcia@lists.infradead.org Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/m32r_cfc.c | 7 ++----- drivers/pcmcia/m32r_pcc.c | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c index 70b089430fcc..9a4940e56e2f 100644 --- a/drivers/pcmcia/m32r_cfc.c +++ b/drivers/pcmcia/m32r_cfc.c @@ -380,11 +380,10 @@ static irqreturn_t pcc_interrupt(int irq, void *dev) return IRQ_RETVAL(handled); } /* pcc_interrupt */ -static void pcc_interrupt_wrapper(u_long data) +static void pcc_interrupt_wrapper(struct timer_list *unused) { pr_debug("m32r_cfc: pcc_interrupt_wrapper:\n"); pcc_interrupt(0, NULL); - init_timer(&poll_timer); poll_timer.expires = jiffies + poll_interval; add_timer(&poll_timer); } @@ -758,9 +757,7 @@ static int __init init_m32r_pcc(void) /* Finally, schedule a polling interrupt */ if (poll_interval != 0) { - poll_timer.function = pcc_interrupt_wrapper; - poll_timer.data = 0; - init_timer(&poll_timer); + timer_setup(&poll_timer, pcc_interrupt_wrapper, 0); poll_timer.expires = jiffies + poll_interval; add_timer(&poll_timer); } diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c index e50bbf826188..c2239a7e383a 100644 --- a/drivers/pcmcia/m32r_pcc.c +++ b/drivers/pcmcia/m32r_pcc.c @@ -386,10 +386,9 @@ static irqreturn_t pcc_interrupt(int irq, void *dev) return IRQ_RETVAL(handled); } /* pcc_interrupt */ -static void pcc_interrupt_wrapper(u_long data) +static void pcc_interrupt_wrapper(struct timer_list *unused) { pcc_interrupt(0, NULL); - init_timer(&poll_timer); poll_timer.expires = jiffies + poll_interval; add_timer(&poll_timer); } @@ -729,9 +728,7 @@ static int __init init_m32r_pcc(void) /* Finally, schedule a polling interrupt */ if (poll_interval != 0) { - poll_timer.function = pcc_interrupt_wrapper; - poll_timer.data = 0; - init_timer(&poll_timer); + timer_setup(&poll_timer, pcc_interrupt_wrapper, 0); poll_timer.expires = jiffies + poll_interval; add_timer(&poll_timer); } -- cgit v1.2.3-58-ga151 From 421eb12ead322d66b469b8bf658eca2213f409f5 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 13 Oct 2017 09:58:11 -0400 Subject: tracing, mei: Remove unused trace event mei_pci_cfg_write Commit a96c548291 ("mei: trace pci configuration space io") added the trace event mei_pci_cfg_write but never used it. As trace events that are defined take up space for data structures and functions created for them, it is a waste of memory to have one defined but not used. Remove this trace event. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/mei-trace.c | 1 - drivers/misc/mei/mei-trace.h | 19 ------------------- 2 files changed, 20 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/mei/mei-trace.c b/drivers/misc/mei/mei-trace.c index e19e6acb191b..374edde72a14 100644 --- a/drivers/misc/mei/mei-trace.c +++ b/drivers/misc/mei/mei-trace.c @@ -23,5 +23,4 @@ EXPORT_TRACEPOINT_SYMBOL(mei_reg_read); EXPORT_TRACEPOINT_SYMBOL(mei_reg_write); EXPORT_TRACEPOINT_SYMBOL(mei_pci_cfg_read); -EXPORT_TRACEPOINT_SYMBOL(mei_pci_cfg_write); #endif /* __CHECKER__ */ diff --git a/drivers/misc/mei/mei-trace.h b/drivers/misc/mei/mei-trace.h index 7d2d5d4a1624..b52e9b97a7c0 100644 --- a/drivers/misc/mei/mei-trace.h +++ b/drivers/misc/mei/mei-trace.h @@ -83,25 +83,6 @@ TRACE_EVENT(mei_pci_cfg_read, __get_str(dev), __entry->reg, __entry->offs, __entry->val) ); -TRACE_EVENT(mei_pci_cfg_write, - TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val), - TP_ARGS(dev, reg, offs, val), - TP_STRUCT__entry( - __string(dev, dev_name(dev)) - __field(const char *, reg) - __field(u32, offs) - __field(u32, val) - ), - TP_fast_assign( - __assign_str(dev, dev_name(dev)) - __entry->reg = reg; - __entry->offs = offs; - __entry->val = val; - ), - TP_printk("[%s] pci cfg write %s[%#x] = %#x", - __get_str(dev), __entry->reg, __entry->offs, __entry->val) -); - #endif /* _MEI_TRACE_H_ */ /* This part must be outside protection */ -- cgit v1.2.3-58-ga151 From c932806c65f3b6712133f6433f9b7c31a6ca0d0b Mon Sep 17 00:00:00 2001 From: Bhumika Goyal Date: Sun, 15 Oct 2017 22:04:23 +0100 Subject: parport: make parport_ip32_ops const and __initconst Make this const as it is only used during a copy operation. This usage is inside init function and the structure is not referenced after initialisation, so make it __initconst too. Signed-off-by: Bhumika Goyal Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_ip32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/parport/parport_ip32.c b/drivers/parport/parport_ip32.c index 0186db7680d4..62873070f988 100644 --- a/drivers/parport/parport_ip32.c +++ b/drivers/parport/parport_ip32.c @@ -1769,7 +1769,7 @@ stop: /*--- Default parport operations ---------------------------------------*/ -static __initdata struct parport_operations parport_ip32_ops = { +static const struct parport_operations parport_ip32_ops __initconst = { .write_data = parport_ip32_write_data, .read_data = parport_ip32_read_data, -- cgit v1.2.3-58-ga151 From 6ae33b9c05dd049b96218930c104e0ce809363b6 Mon Sep 17 00:00:00 2001 From: Sherry Yang Date: Sat, 16 Sep 2017 01:11:56 -0400 Subject: android: binder: Remove unused vma argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The vma argument in update_page_range is no longer used after 74310e06 ("android: binder: Move buffer out of area shared with user space"), since mmap_handler no longer calls update_page_range with a vma. Acked-by: Arve Hjønnevåg Signed-off-by: Sherry Yang Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder_alloc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 064f5e31ec55..b87ecf77f9d1 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -186,12 +186,12 @@ struct binder_buffer *binder_alloc_prepare_to_free(struct binder_alloc *alloc, } static int binder_update_page_range(struct binder_alloc *alloc, int allocate, - void *start, void *end, - struct vm_area_struct *vma) + void *start, void *end) { void *page_addr; unsigned long user_page_addr; struct binder_lru_page *page; + struct vm_area_struct *vma = NULL; struct mm_struct *mm = NULL; bool need_mm = false; @@ -215,7 +215,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, } } - if (!vma && need_mm) + if (need_mm) mm = get_task_mm(alloc->tsk); if (mm) { @@ -442,7 +442,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct binder_alloc *alloc, if (end_page_addr > has_page_addr) end_page_addr = has_page_addr; ret = binder_update_page_range(alloc, 1, - (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr, NULL); + (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr); if (ret) return ERR_PTR(ret); @@ -483,7 +483,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct binder_alloc *alloc, err_alloc_buf_struct_failed: binder_update_page_range(alloc, 0, (void *)PAGE_ALIGN((uintptr_t)buffer->data), - end_page_addr, NULL); + end_page_addr); return ERR_PTR(-ENOMEM); } @@ -567,8 +567,7 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc, alloc->pid, buffer->data, prev->data, next->data); binder_update_page_range(alloc, 0, buffer_start_page(buffer), - buffer_start_page(buffer) + PAGE_SIZE, - NULL); + buffer_start_page(buffer) + PAGE_SIZE); } list_del(&buffer->entry); kfree(buffer); @@ -605,8 +604,7 @@ static void binder_free_buf_locked(struct binder_alloc *alloc, binder_update_page_range(alloc, 0, (void *)PAGE_ALIGN((uintptr_t)buffer->data), - (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK), - NULL); + (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK)); rb_erase(&buffer->rb_node, &alloc->allocated_buffers); buffer->free = 1; -- cgit v1.2.3-58-ga151 From de7bbe3d1baea2b28991a514e596f47e885f92d6 Mon Sep 17 00:00:00 2001 From: Sherry Yang Date: Fri, 6 Oct 2017 16:12:05 -0400 Subject: android: binder: Change binder_shrinker to static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit binder_shrinker struct is not used anywhere outside of binder_alloc.c and should be static. Acked-by: Arve Hjønnevåg Signed-off-by: Sherry Yang Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index b87ecf77f9d1..ed0c9dc792eb 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -985,7 +985,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return ret; } -struct shrinker binder_shrinker = { +static struct shrinker binder_shrinker = { .count_objects = binder_shrink_count, .scan_objects = binder_shrink_scan, .seeks = DEFAULT_SEEKS, -- cgit v1.2.3-58-ga151 From f7f84fded6c461d58ca73c85f0cb23a036717110 Mon Sep 17 00:00:00 2001 From: Arvind Yadav Date: Mon, 25 Sep 2017 12:52:11 +0530 Subject: binder: pr_err() strings should end with newlines pr_err() messages should terminated with a new-line to avoid other messages being concatenated onto the end. Signed-off-by: Arvind Yadav Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 0621a95b8597..2e86e66a456f 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2192,7 +2192,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc, off_start, offp - off_start); if (!parent) { - pr_err("transaction release %d bad parent offset", + pr_err("transaction release %d bad parent offset\n", debug_id); continue; } -- cgit v1.2.3-58-ga151 From 33d426a957dfc9bea13c4e05d0319b1d0a854586 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 5 Oct 2017 17:35:05 -0700 Subject: vmbus: initialize reserved fields in messages Make sure and initialize reserved fields in messages to host, rather than passing stack junk. Signed-off-by: Stephen Hemminger Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 894b67ac2cae..a406beb10dd0 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -745,6 +745,7 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, desc.dataoffset8 = descsize >> 3; /* in 8-bytes granularity */ desc.length8 = (u16)(packetlen_aligned >> 3); desc.transactionid = requestid; + desc.reserved = 0; desc.rangecount = pagecount; for (i = 0; i < pagecount; i++) { @@ -788,6 +789,7 @@ int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel, desc->dataoffset8 = desc_size >> 3; /* in 8-bytes granularity */ desc->length8 = (u16)(packetlen_aligned >> 3); desc->transactionid = requestid; + desc->reserved = 0; desc->rangecount = 1; bufferlist[0].iov_base = desc; -- cgit v1.2.3-58-ga151 From 7a15cf2af480440bacf2fc0010f1fa1a1f3980d6 Mon Sep 17 00:00:00 2001 From: Romain Perier Date: Mon, 9 Oct 2017 15:26:38 +0200 Subject: nvmem: rockchip: add support for RK3368 This adds the necessary function for handling support on RK3368 SoCs Signed-off-by: Romain Perier Acked-by: Rob Herring Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt | 1 + drivers/nvmem/rockchip-efuse.c | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt b/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt index 1ff02afdc55a..60bec4782806 100644 --- a/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt +++ b/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt @@ -6,6 +6,7 @@ Required properties: - "rockchip,rk3188-efuse" - for RK3188 SoCs. - "rockchip,rk3228-efuse" - for RK3228 SoCs. - "rockchip,rk3288-efuse" - for RK3288 SoCs. + - "rockchip,rk3368-efuse" - for RK3368 SoCs. - "rockchip,rk3399-efuse" - for RK3399 SoCs. - reg: Should contain the registers location and exact eFuse size - clocks: Should be the clock id of eFuse diff --git a/drivers/nvmem/rockchip-efuse.c b/drivers/nvmem/rockchip-efuse.c index 63e3eb55f3ac..eb4c530c2564 100644 --- a/drivers/nvmem/rockchip-efuse.c +++ b/drivers/nvmem/rockchip-efuse.c @@ -177,6 +177,10 @@ static const struct of_device_id rockchip_efuse_match[] = { .compatible = "rockchip,rk3288-efuse", .data = (void *)&rockchip_rk3288_efuse_read, }, + { + .compatible = "rockchip,rk3368-efuse", + .data = (void *)&rockchip_rk3288_efuse_read, + }, { .compatible = "rockchip,rk3399-efuse", .data = (void *)&rockchip_rk3399_efuse_read, -- cgit v1.2.3-58-ga151 From 9593ad32b8be82f3abd6002336a93c405361b9fd Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Mon, 9 Oct 2017 15:26:40 +0200 Subject: nvmem: meson-efuse: indicate that this driver is only for Meson GX SoCs The current Amlogic Meson eFuse driver only supports the 64-bit SoCs (GXBB and newer). Older SoCs cannot be supported by the same driver because they do not use the meson secure monitor firmware to access the hardware. Signed-off-by: Martin Blumenstingl Signed-off-by: Srinivas Kandagatla Acked-by: Rob Herring Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt | 2 +- drivers/nvmem/Kconfig | 4 ++-- drivers/nvmem/meson-efuse.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt b/Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt index fafd85bd67a6..e3298e18de26 100644 --- a/Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt +++ b/Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt @@ -1,4 +1,4 @@ -= Amlogic eFuse device tree bindings = += Amlogic Meson GX eFuse device tree bindings = Required properties: - compatible: should be "amlogic,meson-gxbb-efuse" diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index ea3044c5d6ee..2a07cf169b52 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -135,11 +135,11 @@ config NVMEM_VF610_OCOTP be called nvmem-vf610-ocotp. config MESON_EFUSE - tristate "Amlogic eFuse Support" + tristate "Amlogic Meson GX eFuse Support" depends on (ARCH_MESON || COMPILE_TEST) && MESON_SM help This is a driver to retrieve specific values from the eFuse found on - the Amlogic Meson SoCs. + the Amlogic Meson GX SoCs. This driver can also be built as a module. If so, the module will be called nvmem_meson_efuse. diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c index 70bfc9839bb2..1ea3cd24a508 100644 --- a/drivers/nvmem/meson-efuse.c +++ b/drivers/nvmem/meson-efuse.c @@ -1,5 +1,5 @@ /* - * Amlogic eFuse Driver + * Amlogic Meson GX eFuse Driver * * Copyright (c) 2016 Endless Computers, Inc. * Author: Carlo Caione @@ -89,5 +89,5 @@ static struct platform_driver meson_efuse_driver = { module_platform_driver(meson_efuse_driver); MODULE_AUTHOR("Carlo Caione "); -MODULE_DESCRIPTION("Amlogic Meson NVMEM driver"); +MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver"); MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-58-ga151 From 8caef1fa9176c4789b74c806434517b3adf7544a Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Mon, 9 Oct 2017 15:26:41 +0200 Subject: nvmem: add a driver for the Amlogic Meson6/Meson8/Meson8b SoCs This adds a driver to access the efuse on Amlogic Meson6, Meson8 and Meson8b SoCs. These SoCs are accessing the efuse IP block directly through the registers in the "secbus" region. This makes it different from the Meson GX efuse driver which uses the "secure monitor" firmware to access the efuse. The efuse on Meson6 can only read one byte at a time, while the efuse on Meson8 and Meson8b always reads 4 bytes at a time. The new driver supports both, but due to lack of hardware Meson6 support was not tested. The hardware also supports writing. However, this is currently not supported by the driver. Signed-off-by: Martin Blumenstingl Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/Kconfig | 10 ++ drivers/nvmem/Makefile | 2 + drivers/nvmem/meson-mx-efuse.c | 265 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 drivers/nvmem/meson-mx-efuse.c (limited to 'drivers') diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 2a07cf169b52..eb09916744bf 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -144,6 +144,16 @@ config MESON_EFUSE This driver can also be built as a module. If so, the module will be called nvmem_meson_efuse. +config MESON_MX_EFUSE + tristate "Amlogic Meson6/Meson8/Meson8b eFuse Support" + depends on ARCH_MESON || COMPILE_TEST + help + This is a driver to retrieve specific values from the eFuse found on + the Amlogic Meson6, Meson8 and Meson8b SoCs. + + This driver can also be built as a module. If so, the module + will be called nvmem_meson_mx_efuse. + config NVMEM_SNVS_LPGPR tristate "Support for Low Power General Purpose Register" depends on SOC_IMX6 || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 4c589184acee..362f394da65d 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -30,5 +30,7 @@ obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o nvmem-vf610-ocotp-y := vf610-ocotp.o obj-$(CONFIG_MESON_EFUSE) += nvmem_meson_efuse.o nvmem_meson_efuse-y := meson-efuse.o +obj-$(CONFIG_MESON_MX_EFUSE) += nvmem_meson_mx_efuse.o +nvmem_meson_mx_efuse-y := meson-mx-efuse.o obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o nvmem_snvs_lpgpr-y := snvs_lpgpr.o diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c new file mode 100644 index 000000000000..a346b4923550 --- /dev/null +++ b/drivers/nvmem/meson-mx-efuse.c @@ -0,0 +1,265 @@ +/* + * Amlogic Meson6, Meson8 and Meson8b eFuse Driver + * + * Copyright (c) 2017 Martin Blumenstingl + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MESON_MX_EFUSE_CNTL1 0x04 +#define MESON_MX_EFUSE_CNTL1_PD_ENABLE BIT(27) +#define MESON_MX_EFUSE_CNTL1_AUTO_RD_BUSY BIT(26) +#define MESON_MX_EFUSE_CNTL1_AUTO_RD_START BIT(25) +#define MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE BIT(24) +#define MESON_MX_EFUSE_CNTL1_BYTE_WR_DATA GENMASK(23, 16) +#define MESON_MX_EFUSE_CNTL1_AUTO_WR_BUSY BIT(14) +#define MESON_MX_EFUSE_CNTL1_AUTO_WR_START BIT(13) +#define MESON_MX_EFUSE_CNTL1_AUTO_WR_ENABLE BIT(12) +#define MESON_MX_EFUSE_CNTL1_BYTE_ADDR_SET BIT(11) +#define MESON_MX_EFUSE_CNTL1_BYTE_ADDR_MASK GENMASK(10, 0) + +#define MESON_MX_EFUSE_CNTL2 0x08 + +#define MESON_MX_EFUSE_CNTL4 0x10 +#define MESON_MX_EFUSE_CNTL4_ENCRYPT_ENABLE BIT(10) + +struct meson_mx_efuse_platform_data { + const char *name; + unsigned int word_size; +}; + +struct meson_mx_efuse { + void __iomem *base; + struct clk *core_clk; + struct nvmem_device *nvmem; + struct nvmem_config config; +}; + +static void meson_mx_efuse_mask_bits(struct meson_mx_efuse *efuse, u32 reg, + u32 mask, u32 set) +{ + u32 data; + + data = readl(efuse->base + reg); + data &= ~mask; + data |= (set & mask); + + writel(data, efuse->base + reg); +} + +static int meson_mx_efuse_hw_enable(struct meson_mx_efuse *efuse) +{ + int err; + + err = clk_prepare_enable(efuse->core_clk); + if (err) + return err; + + /* power up the efuse */ + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_PD_ENABLE, 0); + + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL4, + MESON_MX_EFUSE_CNTL4_ENCRYPT_ENABLE, 0); + + return 0; +} + +static void meson_mx_efuse_hw_disable(struct meson_mx_efuse *efuse) +{ + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_PD_ENABLE, + MESON_MX_EFUSE_CNTL1_PD_ENABLE); + + clk_disable_unprepare(efuse->core_clk); +} + +static int meson_mx_efuse_read_addr(struct meson_mx_efuse *efuse, + unsigned int addr, u32 *value) +{ + int err; + u32 regval; + + /* write the address to read */ + regval = FIELD_PREP(MESON_MX_EFUSE_CNTL1_BYTE_ADDR_MASK, addr); + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_BYTE_ADDR_MASK, regval); + + /* inform the hardware that we changed the address */ + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_BYTE_ADDR_SET, + MESON_MX_EFUSE_CNTL1_BYTE_ADDR_SET); + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_BYTE_ADDR_SET, 0); + + /* start the read process */ + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_AUTO_RD_START, + MESON_MX_EFUSE_CNTL1_AUTO_RD_START); + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_AUTO_RD_START, 0); + + /* + * perform a dummy read to ensure that the HW has the RD_BUSY bit set + * when polling for the status below. + */ + readl(efuse->base + MESON_MX_EFUSE_CNTL1); + + err = readl_poll_timeout_atomic(efuse->base + MESON_MX_EFUSE_CNTL1, + regval, + (!(regval & MESON_MX_EFUSE_CNTL1_AUTO_RD_BUSY)), + 1, 1000); + if (err) { + dev_err(efuse->config.dev, + "Timeout while reading efuse address %u\n", addr); + return err; + } + + *value = readl(efuse->base + MESON_MX_EFUSE_CNTL2); + + return 0; +} + +static int meson_mx_efuse_read(void *context, unsigned int offset, + void *buf, size_t bytes) +{ + struct meson_mx_efuse *efuse = context; + u32 tmp; + int err, i, addr; + + err = meson_mx_efuse_hw_enable(efuse); + if (err) + return err; + + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE, + MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE); + + for (i = offset; i < offset + bytes; i += efuse->config.word_size) { + addr = i / efuse->config.word_size; + + err = meson_mx_efuse_read_addr(efuse, addr, &tmp); + if (err) + break; + + memcpy(buf + i, &tmp, efuse->config.word_size); + } + + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1, + MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE, 0); + + meson_mx_efuse_hw_disable(efuse); + + return err; +} + +static const struct meson_mx_efuse_platform_data meson6_efuse_data = { + .name = "meson6-efuse", + .word_size = 1, +}; + +static const struct meson_mx_efuse_platform_data meson8_efuse_data = { + .name = "meson8-efuse", + .word_size = 4, +}; + +static const struct meson_mx_efuse_platform_data meson8b_efuse_data = { + .name = "meson8b-efuse", + .word_size = 4, +}; + +static const struct of_device_id meson_mx_efuse_match[] = { + { .compatible = "amlogic,meson6-efuse", .data = &meson6_efuse_data }, + { .compatible = "amlogic,meson8-efuse", .data = &meson8_efuse_data }, + { .compatible = "amlogic,meson8b-efuse", .data = &meson8b_efuse_data }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, meson_mx_efuse_match); + +static int meson_mx_efuse_probe(struct platform_device *pdev) +{ + const struct meson_mx_efuse_platform_data *drvdata; + struct meson_mx_efuse *efuse; + struct resource *res; + + drvdata = of_device_get_match_data(&pdev->dev); + if (!drvdata) + return -EINVAL; + + efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); + if (!efuse) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + efuse->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(efuse->base)) + return PTR_ERR(efuse->base); + + efuse->config.name = devm_kstrdup(&pdev->dev, drvdata->name, + GFP_KERNEL); + efuse->config.owner = THIS_MODULE; + efuse->config.dev = &pdev->dev; + efuse->config.priv = efuse; + efuse->config.stride = drvdata->word_size; + efuse->config.word_size = drvdata->word_size; + efuse->config.size = SZ_512; + efuse->config.read_only = true; + efuse->config.reg_read = meson_mx_efuse_read; + + efuse->core_clk = devm_clk_get(&pdev->dev, "core"); + if (IS_ERR(efuse->core_clk)) { + dev_err(&pdev->dev, "Failed to get core clock\n"); + return PTR_ERR(efuse->core_clk); + } + + efuse->nvmem = nvmem_register(&efuse->config); + if (IS_ERR(efuse->nvmem)) + return PTR_ERR(efuse->nvmem); + + platform_set_drvdata(pdev, efuse); + + return 0; +} + +static int meson_mx_efuse_remove(struct platform_device *pdev) +{ + struct meson_mx_efuse *efuse = platform_get_drvdata(pdev); + + return nvmem_unregister(efuse->nvmem); +} + +static struct platform_driver meson_mx_efuse_driver = { + .probe = meson_mx_efuse_probe, + .remove = meson_mx_efuse_remove, + .driver = { + .name = "meson-mx-efuse", + .of_match_table = meson_mx_efuse_match, + }, +}; + +module_platform_driver(meson_mx_efuse_driver); + +MODULE_AUTHOR("Martin Blumenstingl "); +MODULE_DESCRIPTION("Amlogic Meson MX eFuse NVMEM driver"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-58-ga151 From 31c5c870a1120960ec4157e6a5ea34686c77f6b8 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 20 Oct 2017 06:31:27 -0700 Subject: lkdtm: Convert from jprobe to kprobe The jprobe subsystem is being removed, so convert to using kprobe instead. Cc: Masami Hiramatsu Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/misc/lkdtm_core.c | 154 ++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 109 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c index 981b3ef71e47..ed7f0c61c59a 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -56,122 +56,54 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf, size_t count, loff_t *off); #ifdef CONFIG_KPROBES -static void lkdtm_handler(void); +static int lkdtm_kprobe_handler(struct kprobe *kp, struct pt_regs *regs); static ssize_t lkdtm_debugfs_entry(struct file *f, const char __user *user_buf, size_t count, loff_t *off); - - -/* jprobe entry point handlers. */ -static unsigned int jp_do_irq(unsigned int irq) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} - -static irqreturn_t jp_handle_irq_event(unsigned int irq, - struct irqaction *action) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} - -static void jp_tasklet_action(struct softirq_action *a) -{ - lkdtm_handler(); - jprobe_return(); -} - -static void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) -{ - lkdtm_handler(); - jprobe_return(); -} - -struct scan_control; - -static unsigned long jp_shrink_inactive_list(unsigned long max_scan, - struct zone *zone, - struct scan_control *sc) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} - -static int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim, - const enum hrtimer_mode mode) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} - -static int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} - -# ifdef CONFIG_IDE -static int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file, - struct block_device *bdev, unsigned int cmd, - unsigned long arg) -{ - lkdtm_handler(); - jprobe_return(); - return 0; -} -# endif +# define CRASHPOINT_KPROBE(_symbol) \ + .kprobe = { \ + .symbol_name = (_symbol), \ + .pre_handler = lkdtm_kprobe_handler, \ + }, +# define CRASHPOINT_WRITE(_symbol) \ + (_symbol) ? lkdtm_debugfs_entry : direct_entry +#else +# define CRASHPOINT_KPROBE(_symbol) +# define CRASHPOINT_WRITE(_symbol) direct_entry #endif /* Crash points */ struct crashpoint { const char *name; const struct file_operations fops; - struct jprobe jprobe; + struct kprobe kprobe; }; -#define CRASHPOINT(_name, _write, _symbol, _entry) \ +#define CRASHPOINT(_name, _symbol) \ { \ .name = _name, \ .fops = { \ .read = lkdtm_debugfs_read, \ .llseek = generic_file_llseek, \ .open = lkdtm_debugfs_open, \ - .write = _write, \ - }, \ - .jprobe = { \ - .kp.symbol_name = _symbol, \ - .entry = (kprobe_opcode_t *)_entry, \ + .write = CRASHPOINT_WRITE(_symbol) \ }, \ + CRASHPOINT_KPROBE(_symbol) \ } /* Define the possible places where we can trigger a crash point. */ -struct crashpoint crashpoints[] = { - CRASHPOINT("DIRECT", direct_entry, - NULL, NULL), +static struct crashpoint crashpoints[] = { + CRASHPOINT("DIRECT", NULL), #ifdef CONFIG_KPROBES - CRASHPOINT("INT_HARDWARE_ENTRY", lkdtm_debugfs_entry, - "do_IRQ", jp_do_irq), - CRASHPOINT("INT_HW_IRQ_EN", lkdtm_debugfs_entry, - "handle_IRQ_event", jp_handle_irq_event), - CRASHPOINT("INT_TASKLET_ENTRY", lkdtm_debugfs_entry, - "tasklet_action", jp_tasklet_action), - CRASHPOINT("FS_DEVRW", lkdtm_debugfs_entry, - "ll_rw_block", jp_ll_rw_block), - CRASHPOINT("MEM_SWAPOUT", lkdtm_debugfs_entry, - "shrink_inactive_list", jp_shrink_inactive_list), - CRASHPOINT("TIMERADD", lkdtm_debugfs_entry, - "hrtimer_start", jp_hrtimer_start), - CRASHPOINT("SCSI_DISPATCH_CMD", lkdtm_debugfs_entry, - "scsi_dispatch_cmd", jp_scsi_dispatch_cmd), + CRASHPOINT("INT_HARDWARE_ENTRY", "do_IRQ"), + CRASHPOINT("INT_HW_IRQ_EN", "handle_IRQ_event"), + CRASHPOINT("INT_TASKLET_ENTRY", "tasklet_action"), + CRASHPOINT("FS_DEVRW", "ll_rw_block"), + CRASHPOINT("MEM_SWAPOUT", "shrink_inactive_list"), + CRASHPOINT("TIMERADD", "hrtimer_start"), + CRASHPOINT("SCSI_DISPATCH_CMD", "scsi_dispatch_cmd"), # ifdef CONFIG_IDE - CRASHPOINT("IDE_CORE_CP", lkdtm_debugfs_entry, - "generic_ide_ioctl", jp_generic_ide_ioctl), + CRASHPOINT("IDE_CORE_CP", "generic_ide_ioctl"), # endif #endif }; @@ -254,8 +186,8 @@ struct crashtype crashtypes[] = { }; -/* Global jprobe entry and crashtype. */ -static struct jprobe *lkdtm_jprobe; +/* Global kprobe entry and crashtype. */ +static struct kprobe *lkdtm_kprobe; struct crashpoint *lkdtm_crashpoint; struct crashtype *lkdtm_crashtype; @@ -298,7 +230,8 @@ static struct crashtype *find_crashtype(const char *name) */ static noinline void lkdtm_do_action(struct crashtype *crashtype) { - BUG_ON(!crashtype || !crashtype->func); + if (WARN_ON(!crashtype || !crashtype->func)) + return; crashtype->func(); } @@ -308,22 +241,22 @@ static int lkdtm_register_cpoint(struct crashpoint *crashpoint, int ret; /* If this doesn't have a symbol, just call immediately. */ - if (!crashpoint->jprobe.kp.symbol_name) { + if (!crashpoint->kprobe.symbol_name) { lkdtm_do_action(crashtype); return 0; } - if (lkdtm_jprobe != NULL) - unregister_jprobe(lkdtm_jprobe); + if (lkdtm_kprobe != NULL) + unregister_kprobe(lkdtm_kprobe); lkdtm_crashpoint = crashpoint; lkdtm_crashtype = crashtype; - lkdtm_jprobe = &crashpoint->jprobe; - ret = register_jprobe(lkdtm_jprobe); + lkdtm_kprobe = &crashpoint->kprobe; + ret = register_kprobe(lkdtm_kprobe); if (ret < 0) { - pr_info("Couldn't register jprobe %s\n", - crashpoint->jprobe.kp.symbol_name); - lkdtm_jprobe = NULL; + pr_info("Couldn't register kprobe %s\n", + crashpoint->kprobe.symbol_name); + lkdtm_kprobe = NULL; lkdtm_crashpoint = NULL; lkdtm_crashtype = NULL; } @@ -336,13 +269,14 @@ static int lkdtm_register_cpoint(struct crashpoint *crashpoint, static int crash_count = DEFAULT_COUNT; static DEFINE_SPINLOCK(crash_count_lock); -/* Called by jprobe entry points. */ -static void lkdtm_handler(void) +/* Called by kprobe entry points. */ +static int lkdtm_kprobe_handler(struct kprobe *kp, struct pt_regs *regs) { unsigned long flags; bool do_it = false; - BUG_ON(!lkdtm_crashpoint || !lkdtm_crashtype); + if (WARN_ON(!lkdtm_crashpoint || !lkdtm_crashtype)) + return 0; spin_lock_irqsave(&crash_count_lock, flags); crash_count--; @@ -357,6 +291,8 @@ static void lkdtm_handler(void) if (do_it) lkdtm_do_action(lkdtm_crashtype); + + return 0; } static ssize_t lkdtm_debugfs_entry(struct file *f, @@ -556,8 +492,8 @@ static void __exit lkdtm_module_exit(void) /* Handle test-specific clean-up. */ lkdtm_usercopy_exit(); - if (lkdtm_jprobe != NULL) - unregister_jprobe(lkdtm_jprobe); + if (lkdtm_kprobe != NULL) + unregister_kprobe(lkdtm_kprobe); pr_info("Crash point unregistered\n"); } -- cgit v1.2.3-58-ga151 From 75f98b7ab748a6f604d667d84ec46acc452fdfc1 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 20 Oct 2017 06:31:49 -0700 Subject: lkdtm: Constify the crashtypes table Since nothing in the crashtypes table ever changes, mark it const. Adds some missing "static" markings as well. Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/misc/lkdtm_core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c index ed7f0c61c59a..ba92291508dc 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -122,7 +122,7 @@ struct crashtype { } /* Define the possible types of crashes that can be triggered. */ -struct crashtype crashtypes[] = { +static const struct crashtype crashtypes[] = { CRASHTYPE(PANIC), CRASHTYPE(BUG), CRASHTYPE(WARNING), @@ -188,8 +188,8 @@ struct crashtype crashtypes[] = { /* Global kprobe entry and crashtype. */ static struct kprobe *lkdtm_kprobe; -struct crashpoint *lkdtm_crashpoint; -struct crashtype *lkdtm_crashtype; +static struct crashpoint *lkdtm_crashpoint; +static const struct crashtype *lkdtm_crashtype; /* Module parameters */ static int recur_count = -1; @@ -212,7 +212,7 @@ MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ /* Return the crashtype number or NULL if the name is invalid */ -static struct crashtype *find_crashtype(const char *name) +static const struct crashtype *find_crashtype(const char *name) { int i; @@ -228,7 +228,7 @@ static struct crashtype *find_crashtype(const char *name) * This is forced noinline just so it distinctly shows up in the stackdump * which makes validation of expected lkdtm crashes easier. */ -static noinline void lkdtm_do_action(struct crashtype *crashtype) +static noinline void lkdtm_do_action(const struct crashtype *crashtype) { if (WARN_ON(!crashtype || !crashtype->func)) return; @@ -236,7 +236,7 @@ static noinline void lkdtm_do_action(struct crashtype *crashtype) } static int lkdtm_register_cpoint(struct crashpoint *crashpoint, - struct crashtype *crashtype) + const struct crashtype *crashtype) { int ret; @@ -300,7 +300,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f, size_t count, loff_t *off) { struct crashpoint *crashpoint = file_inode(f)->i_private; - struct crashtype *crashtype = NULL; + const struct crashtype *crashtype = NULL; char *buf; int err; @@ -368,7 +368,7 @@ static int lkdtm_debugfs_open(struct inode *inode, struct file *file) static ssize_t direct_entry(struct file *f, const char __user *user_buf, size_t count, loff_t *off) { - struct crashtype *crashtype; + const struct crashtype *crashtype; char *buf; if (count >= PAGE_SIZE) @@ -404,7 +404,7 @@ static struct dentry *lkdtm_debugfs_root; static int __init lkdtm_module_init(void) { struct crashpoint *crashpoint = NULL; - struct crashtype *crashtype = NULL; + const struct crashtype *crashtype = NULL; int ret = -EINVAL; int i; -- cgit v1.2.3-58-ga151 From de4ce2d1ad1bb3304d4107160c9551b7fd8d8ec5 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Fri, 20 Oct 2017 17:27:49 -0200 Subject: genwqe: Take R/W permissions into account when dealing with memory pages Currently we assume userspace pages are always writable when doing memory pinning. This is not true, specially since userspace applications may allocate their memory the way they want, we have no control over it. If a read-only page is set for pinning, currently the driver fails due to get_user_pages_fast() refusing to map read-only pages as writable. This patch changes this behavior, by taking the permission flags of the pages into account in both pinning/unpinning process, as well as in the DMA data copy-back to userpace (which we shouldn't try to do blindly, since it will fail in case of read-only-pages). Signed-off-by: Frank Haverkamp Signed-off-by: Guilherme G. Piccoli Signed-off-by: Greg Kroah-Hartman --- drivers/misc/genwqe/card_base.h | 7 ++++++- drivers/misc/genwqe/card_dev.c | 6 +++++- drivers/misc/genwqe/card_utils.c | 43 +++++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/genwqe/card_base.h b/drivers/misc/genwqe/card_base.h index 5813b5f25006..3743c87f8ab9 100644 --- a/drivers/misc/genwqe/card_base.h +++ b/drivers/misc/genwqe/card_base.h @@ -182,6 +182,7 @@ struct dma_mapping { struct list_head card_list; /* list of usr_maps for card */ struct list_head pin_list; /* list of pinned memory for dev */ + int write; /* writable map? useful in unmapping */ }; static inline void genwqe_mapping_init(struct dma_mapping *m, @@ -189,6 +190,7 @@ static inline void genwqe_mapping_init(struct dma_mapping *m, { memset(m, 0, sizeof(*m)); m->type = type; + m->write = 1; /* Assume the maps we create are R/W */ } /** @@ -347,6 +349,7 @@ enum genwqe_requ_state { * @user_size: size of user-space memory area * @page: buffer for partial pages if needed * @page_dma_addr: dma address partial pages + * @write: should we write it back to userspace? */ struct genwqe_sgl { dma_addr_t sgl_dma_addr; @@ -356,6 +359,8 @@ struct genwqe_sgl { void __user *user_addr; /* user-space base-address */ size_t user_size; /* size of memory area */ + int write; + unsigned long nr_pages; unsigned long fpage_offs; size_t fpage_size; @@ -369,7 +374,7 @@ struct genwqe_sgl { }; int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, - void __user *user_addr, size_t user_size); + void __user *user_addr, size_t user_size, int write); int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, dma_addr_t *dma_list); diff --git a/drivers/misc/genwqe/card_dev.c b/drivers/misc/genwqe/card_dev.c index dd4617764f14..3ecfa35457e0 100644 --- a/drivers/misc/genwqe/card_dev.c +++ b/drivers/misc/genwqe/card_dev.c @@ -942,6 +942,10 @@ static int ddcb_cmd_fixups(struct genwqe_file *cfile, struct ddcb_requ *req) genwqe_mapping_init(m, GENWQE_MAPPING_SGL_TEMP); + + if (ats_flags == ATS_TYPE_SGL_RD) + m->write = 0; + rc = genwqe_user_vmap(cd, m, (void *)u_addr, u_size, req); if (rc != 0) @@ -954,7 +958,7 @@ static int ddcb_cmd_fixups(struct genwqe_file *cfile, struct ddcb_requ *req) /* create genwqe style scatter gather list */ rc = genwqe_alloc_sync_sgl(cd, &req->sgls[i], (void __user *)u_addr, - u_size); + u_size, m->write); if (rc != 0) goto err_out; diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c index 147b83011b58..5c0d917636f7 100644 --- a/drivers/misc/genwqe/card_utils.c +++ b/drivers/misc/genwqe/card_utils.c @@ -296,7 +296,7 @@ static int genwqe_sgl_size(int num_pages) * from user-space into the cached pages. */ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, - void __user *user_addr, size_t user_size) + void __user *user_addr, size_t user_size, int write) { int rc; struct pci_dev *pci_dev = cd->pci_dev; @@ -312,6 +312,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, sgl->user_addr = user_addr; sgl->user_size = user_size; + sgl->write = write; sgl->sgl_size = genwqe_sgl_size(sgl->nr_pages); if (get_order(sgl->sgl_size) > MAX_ORDER) { @@ -476,14 +477,20 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, int genwqe_free_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl) { int rc = 0; + size_t offset; + unsigned long res; struct pci_dev *pci_dev = cd->pci_dev; if (sgl->fpage) { - if (copy_to_user(sgl->user_addr, sgl->fpage + sgl->fpage_offs, - sgl->fpage_size)) { - dev_err(&pci_dev->dev, "[%s] err: copying fpage!\n", - __func__); - rc = -EFAULT; + if (sgl->write) { + res = copy_to_user(sgl->user_addr, + sgl->fpage + sgl->fpage_offs, sgl->fpage_size); + if (res) { + dev_err(&pci_dev->dev, + "[%s] err: copying fpage! (res=%lu)\n", + __func__, res); + rc = -EFAULT; + } } __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, sgl->fpage_dma_addr); @@ -491,12 +498,16 @@ int genwqe_free_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl) sgl->fpage_dma_addr = 0; } if (sgl->lpage) { - if (copy_to_user(sgl->user_addr + sgl->user_size - - sgl->lpage_size, sgl->lpage, - sgl->lpage_size)) { - dev_err(&pci_dev->dev, "[%s] err: copying lpage!\n", - __func__); - rc = -EFAULT; + if (sgl->write) { + offset = sgl->user_size - sgl->lpage_size; + res = copy_to_user(sgl->user_addr + offset, sgl->lpage, + sgl->lpage_size); + if (res) { + dev_err(&pci_dev->dev, + "[%s] err: copying lpage! (res=%lu)\n", + __func__, res); + rc = -EFAULT; + } } __genwqe_free_consistent(cd, PAGE_SIZE, sgl->lpage, sgl->lpage_dma_addr); @@ -599,14 +610,14 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, /* pin user pages in memory */ rc = get_user_pages_fast(data & PAGE_MASK, /* page aligned addr */ m->nr_pages, - 1, /* write by caller */ + m->write, /* readable/writable */ m->page_list); /* ptrs to pages */ if (rc < 0) goto fail_get_user_pages; /* assumption: get_user_pages can be killed by signals. */ if (rc < m->nr_pages) { - free_user_pages(m->page_list, rc, 0); + free_user_pages(m->page_list, rc, m->write); rc = -EFAULT; goto fail_get_user_pages; } @@ -618,7 +629,7 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, return 0; fail_free_user_pages: - free_user_pages(m->page_list, m->nr_pages, 0); + free_user_pages(m->page_list, m->nr_pages, m->write); fail_get_user_pages: kfree(m->page_list); @@ -651,7 +662,7 @@ int genwqe_user_vunmap(struct genwqe_dev *cd, struct dma_mapping *m, genwqe_unmap_pages(cd, m->dma_list, m->nr_pages); if (m->page_list) { - free_user_pages(m->page_list, m->nr_pages, 1); + free_user_pages(m->page_list, m->nr_pages, m->write); kfree(m->page_list); m->page_list = NULL; -- cgit v1.2.3-58-ga151 From 6981fbf3780366093858c5d2dcdaadcd1fbb04be Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 29 Oct 2017 11:33:40 -0700 Subject: Drivers: hv: vmbus: Expose per-channel interrupts and events counters When investigating performance, it is useful to be able to look at the number of host and guest events per-channel. This is equivalent to per-device interrupt statistics. Signed-off-by: Stephen Hemminger Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/stable/sysfs-bus-vmbus | 26 ++++++++++++++++++++------ drivers/hv/connection.c | 2 ++ drivers/hv/vmbus_drv.c | 16 ++++++++++++++++ include/linux/hyperv.h | 4 ++++ 4 files changed, 42 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus index 0ebd8a1537a0..d4077cc60d55 100644 --- a/Documentation/ABI/stable/sysfs-bus-vmbus +++ b/Documentation/ABI/stable/sysfs-bus-vmbus @@ -61,39 +61,53 @@ Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Inbound channel signaling state -Users: Debuggig tools +Users: Debugging tools What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Channel signaling latency -Users: Debuggig tools +Users: Debugging tools What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Outbound channel signaling state -Users: Debuggig tools +Users: Debugging tools What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Channel interrupt pending state -Users: Debuggig tools +Users: Debugging tools What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Bytes availabble to read -Users: Debuggig tools +Users: Debugging tools What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger Description: Bytes availabble to write -Users: Debuggig tools +Users: Debugging tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/events +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Number of times we have signaled the host +Users: Debugging tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/relid/interrupts +Date: September. 2017 +KernelVersion: 4.14 +Contact: Stephen Hemminger +Description: Number of times we have taken an interrupt (incoming) +Users: Debugging tools diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index f41901f80b64..b06a6b796819 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -409,6 +409,8 @@ void vmbus_set_event(struct vmbus_channel *channel) if (!channel->is_dedicated_interrupt) vmbus_send_interrupt(child_relid); + ++channel->sig_events; + hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event); } EXPORT_SYMBOL_GPL(vmbus_set_event); diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 1da8e818f4de..bca8188f3c8c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -944,6 +944,8 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) if (channel->rescind) continue; + ++channel->interrupts; + switch (channel->callback_mode) { case HV_CALL_ISR: vmbus_channel_isr(channel); @@ -1237,6 +1239,18 @@ static ssize_t channel_latency_show(const struct vmbus_channel *channel, } VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL); +static ssize_t channel_interrupts_show(const struct vmbus_channel *channel, char *buf) +{ + return sprintf(buf, "%llu\n", channel->interrupts); +} +VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL); + +static ssize_t channel_events_show(const struct vmbus_channel *channel, char *buf) +{ + return sprintf(buf, "%llu\n", channel->sig_events); +} +VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL); + static struct attribute *vmbus_chan_attrs[] = { &chan_attr_out_mask.attr, &chan_attr_in_mask.attr, @@ -1245,6 +1259,8 @@ static struct attribute *vmbus_chan_attrs[] = { &chan_attr_cpu.attr, &chan_attr_pending.attr, &chan_attr_latency.attr, + &chan_attr_interrupts.attr, + &chan_attr_events.attr, NULL }; diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index ea6b5586ad77..f3e97c5f94c9 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -719,6 +719,10 @@ struct vmbus_channel { struct vmbus_close_msg close_msg; + /* Statistics */ + u64 interrupts; /* Host to Guest interrupts */ + u64 sig_events; /* Guest to Host events */ + /* Channel callback's invoked in softirq context */ struct tasklet_struct callback_event; void (*onchannel_callback)(void *context); -- cgit v1.2.3-58-ga151 From 7ed4325a44ea5a683547d4ce62578f812938cf94 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Sun, 29 Oct 2017 11:33:41 -0700 Subject: Drivers: hv: vmbus: Make panic reporting to be more useful Hyper-V allows the guest to report panic and the guest can pass additional information. All this is logged on the host. Currently Linux is passing back information that is not particularly useful. Make the following changes: 1. Windows uses crash MSR P0 to report bugcheck code. Follow the same convention for Linux as well. 2. It will be useful to know the gust ID of the Linux guest that has paniced. Pass back this information. These changes will help in better supporting Linux on Hyper-V Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- arch/x86/hyperv/hv_init.c | 15 +++++++++------ arch/x86/include/asm/mshyperv.h | 2 +- drivers/hv/vmbus_drv.c | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index a5db63f728a2..aeb8edf32e2b 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -210,9 +210,10 @@ void hyperv_cleanup(void) } EXPORT_SYMBOL_GPL(hyperv_cleanup); -void hyperv_report_panic(struct pt_regs *regs) +void hyperv_report_panic(struct pt_regs *regs, long err) { static bool panic_reported; + u64 guest_id; /* * We prefer to report panic on 'die' chain as we have proper @@ -223,11 +224,13 @@ void hyperv_report_panic(struct pt_regs *regs) return; panic_reported = true; - wrmsrl(HV_X64_MSR_CRASH_P0, regs->ip); - wrmsrl(HV_X64_MSR_CRASH_P1, regs->ax); - wrmsrl(HV_X64_MSR_CRASH_P2, regs->bx); - wrmsrl(HV_X64_MSR_CRASH_P3, regs->cx); - wrmsrl(HV_X64_MSR_CRASH_P4, regs->dx); + rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id); + + wrmsrl(HV_X64_MSR_CRASH_P0, err); + wrmsrl(HV_X64_MSR_CRASH_P1, guest_id); + wrmsrl(HV_X64_MSR_CRASH_P2, regs->ip); + wrmsrl(HV_X64_MSR_CRASH_P3, regs->ax); + wrmsrl(HV_X64_MSR_CRASH_P4, regs->sp); /* * Let Hyper-V know there is crash data available diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 530f448fddaf..bd89104a5533 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -310,7 +310,7 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number) void hyperv_init(void); void hyperv_setup_mmu_ops(void); void hyper_alloc_mmu(void); -void hyperv_report_panic(struct pt_regs *regs); +void hyperv_report_panic(struct pt_regs *regs, long err); bool hv_is_hypercall_page_setup(void); void hyperv_cleanup(void); #else /* CONFIG_HYPERV */ diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index bca8188f3c8c..8fe13cd76acf 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -65,7 +65,7 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned long val, regs = current_pt_regs(); - hyperv_report_panic(regs); + hyperv_report_panic(regs, val); return NOTIFY_DONE; } @@ -75,7 +75,7 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long val, struct die_args *die = (struct die_args *)args; struct pt_regs *regs = die->regs; - hyperv_report_panic(regs); + hyperv_report_panic(regs, val); return NOTIFY_DONE; } -- cgit v1.2.3-58-ga151 From 7e0471078781dc60a564a442d56b4f846504c43c Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 25 Oct 2017 03:22:57 -0700 Subject: auxdisplay: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Miguel Ojeda Sandonis Signed-off-by: Kees Cook Reviewed-by: Paul Burton Tested-by: Paul Burton Signed-off-by: Greg Kroah-Hartman --- drivers/auxdisplay/img-ascii-lcd.c | 10 ++++------ drivers/auxdisplay/panel.c | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c index 25306fa27251..c9e32d29ec81 100644 --- a/drivers/auxdisplay/img-ascii-lcd.c +++ b/drivers/auxdisplay/img-ascii-lcd.c @@ -229,9 +229,9 @@ MODULE_DEVICE_TABLE(of, img_ascii_lcd_matches); * Scroll the current message along the LCD by one character, rearming the * timer if required. */ -static void img_ascii_lcd_scroll(unsigned long arg) +static void img_ascii_lcd_scroll(struct timer_list *t) { - struct img_ascii_lcd_ctx *ctx = (struct img_ascii_lcd_ctx *)arg; + struct img_ascii_lcd_ctx *ctx = from_timer(ctx, t, timer); unsigned int i, ch = ctx->scroll_pos; unsigned int num_chars = ctx->cfg->num_chars; @@ -299,7 +299,7 @@ static int img_ascii_lcd_display(struct img_ascii_lcd_ctx *ctx, ctx->scroll_pos = 0; /* update the LCD */ - img_ascii_lcd_scroll((unsigned long)ctx); + img_ascii_lcd_scroll(&ctx->timer); return 0; } @@ -395,9 +395,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev) ctx->scroll_rate = HZ / 2; /* initialise a timer for scrolling the message */ - init_timer(&ctx->timer); - ctx->timer.function = img_ascii_lcd_scroll; - ctx->timer.data = (unsigned long)ctx; + timer_setup(&ctx->timer, img_ascii_lcd_scroll, 0); platform_set_drvdata(pdev, ctx); diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c index 6911acd896d9..ea7869c0d7f9 100644 --- a/drivers/auxdisplay/panel.c +++ b/drivers/auxdisplay/panel.c @@ -1396,7 +1396,7 @@ static void panel_process_inputs(void) } } -static void panel_scan_timer(void) +static void panel_scan_timer(struct timer_list *unused) { if (keypad.enabled && keypad_initialized) { if (spin_trylock_irq(&pprt_lock)) { @@ -1421,7 +1421,7 @@ static void init_scan_timer(void) if (scan_timer.function) return; /* already started */ - setup_timer(&scan_timer, (void *)&panel_scan_timer, 0); + timer_setup(&scan_timer, panel_scan_timer, 0); scan_timer.expires = jiffies + INPUT_POLL_TIME; add_timer(&scan_timer); } -- cgit v1.2.3-58-ga151 From 4e826adcaafa4b599811ddf39b6b814b8e1b4f5e Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 24 Oct 2017 03:23:39 -0700 Subject: drivers/sgi-xp: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Cliff Whickman Signed-off-by: Kees Cook Acked-by: Robin Holt Signed-off-by: Greg Kroah-Hartman --- drivers/misc/sgi-xp/xpc_main.c | 15 ++++++--------- drivers/misc/sgi-xp/xpc_sn2.c | 15 ++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c index 7f327121e6d7..0c775d6fcf59 100644 --- a/drivers/misc/sgi-xp/xpc_main.c +++ b/drivers/misc/sgi-xp/xpc_main.c @@ -172,9 +172,9 @@ struct xpc_arch_operations xpc_arch_ops; * Timer function to enforce the timelimit on the partition disengage. */ static void -xpc_timeout_partition_disengage(unsigned long data) +xpc_timeout_partition_disengage(struct timer_list *t) { - struct xpc_partition *part = (struct xpc_partition *)data; + struct xpc_partition *part = from_timer(part, t, disengage_timer); DBUG_ON(time_is_after_jiffies(part->disengage_timeout)); @@ -190,7 +190,7 @@ xpc_timeout_partition_disengage(unsigned long data) * specify when the next timeout should occur. */ static void -xpc_hb_beater(unsigned long dummy) +xpc_hb_beater(struct timer_list *unused) { xpc_arch_ops.increment_heartbeat(); @@ -205,8 +205,7 @@ static void xpc_start_hb_beater(void) { xpc_arch_ops.heartbeat_init(); - init_timer(&xpc_hb_timer); - xpc_hb_timer.function = xpc_hb_beater; + timer_setup(&xpc_hb_timer, xpc_hb_beater, 0); xpc_hb_beater(0); } @@ -931,10 +930,8 @@ xpc_setup_partitions(void) part->act_state = XPC_P_AS_INACTIVE; XPC_SET_REASON(part, 0, 0); - init_timer(&part->disengage_timer); - part->disengage_timer.function = - xpc_timeout_partition_disengage; - part->disengage_timer.data = (unsigned long)part; + timer_setup(&part->disengage_timer, + xpc_timeout_partition_disengage, 0); part->setup_state = XPC_P_SS_UNSET; init_waitqueue_head(&part->teardown_wq); diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c index 7d71c04fc938..5a12d2a54049 100644 --- a/drivers/misc/sgi-xp/xpc_sn2.c +++ b/drivers/misc/sgi-xp/xpc_sn2.c @@ -323,16 +323,16 @@ xpc_handle_notify_IRQ_sn2(int irq, void *dev_id) * was received. */ static void -xpc_check_for_dropped_notify_IRQ_sn2(struct xpc_partition *part) +xpc_check_for_dropped_notify_IRQ_sn2(struct timer_list *t) { - struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; + struct xpc_partition *part = + from_timer(part, t, sn.sn2.dropped_notify_IRQ_timer); if (xpc_part_ref(part)) { xpc_check_for_sent_chctl_flags_sn2(part); - part_sn2->dropped_notify_IRQ_timer.expires = jiffies + - XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL; - add_timer(&part_sn2->dropped_notify_IRQ_timer); + t->expires = jiffies + XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL; + add_timer(t); xpc_part_deref(part); } } @@ -1232,10 +1232,7 @@ xpc_setup_ch_structures_sn2(struct xpc_partition *part) /* Setup a timer to check for dropped notify IRQs */ timer = &part_sn2->dropped_notify_IRQ_timer; - init_timer(timer); - timer->function = - (void (*)(unsigned long))xpc_check_for_dropped_notify_IRQ_sn2; - timer->data = (unsigned long)part; + timer_setup(timer, xpc_check_for_dropped_notify_IRQ_sn2, 0); timer->expires = jiffies + XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL; add_timer(timer); -- cgit v1.2.3-58-ga151 From 32946cc2d5686d320aab9fb162d8949c767f7519 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 24 Oct 2017 03:23:31 -0700 Subject: drivers/pcmcia: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Florian Fainelli Cc: bcm-kernel-feedback-list@broadcom.com Cc: David Howells Cc: Arnd Bergmann Cc: linux-pcmcia@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook Acked-by: Russell King Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/bcm63xx_pcmcia.c | 6 +++--- drivers/pcmcia/bfin_cf_pcmcia.c | 6 +++--- drivers/pcmcia/i82365.c | 6 ++---- drivers/pcmcia/omap_cf.c | 8 ++++---- drivers/pcmcia/pd6729.c | 7 +++---- drivers/pcmcia/soc_common.c | 7 +++---- drivers/pcmcia/tcic.c | 8 +++----- drivers/pcmcia/yenta_socket.c | 7 +++---- 8 files changed, 24 insertions(+), 31 deletions(-) (limited to 'drivers') diff --git a/drivers/pcmcia/bcm63xx_pcmcia.c b/drivers/pcmcia/bcm63xx_pcmcia.c index 0802e0bc7d0c..16f573173471 100644 --- a/drivers/pcmcia/bcm63xx_pcmcia.c +++ b/drivers/pcmcia/bcm63xx_pcmcia.c @@ -263,12 +263,12 @@ static int bcm63xx_pcmcia_get_status(struct pcmcia_socket *sock, /* * socket polling timer callback */ -static void bcm63xx_pcmcia_poll(unsigned long data) +static void bcm63xx_pcmcia_poll(struct timer_list *t) { struct bcm63xx_pcmcia_socket *skt; unsigned int stat, events; - skt = (struct bcm63xx_pcmcia_socket *)data; + skt = from_timer(skt, t, timer); spin_lock_bh(&skt->lock); @@ -392,7 +392,7 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) sock->map_size = resource_size(skt->common_res); /* initialize polling timer */ - setup_timer(&skt->timer, bcm63xx_pcmcia_poll, (unsigned long)skt); + timer_setup(&skt->timer, bcm63xx_pcmcia_poll, 0); /* initialize pcmcia control register, drive VS[12] to 0, * leave CB IDSEL to the old value since it is set by the PCI diff --git a/drivers/pcmcia/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c index 8b0923fd76c6..00a296d431ba 100644 --- a/drivers/pcmcia/bfin_cf_pcmcia.c +++ b/drivers/pcmcia/bfin_cf_pcmcia.c @@ -86,9 +86,9 @@ static int bfin_cf_ss_init(struct pcmcia_socket *s) } /* the timer is primarily to kick this socket's pccardd */ -static void bfin_cf_timer(unsigned long _cf) +static void bfin_cf_timer(struct timer_list *t) { - struct bfin_cf_socket *cf = (void *)_cf; + struct bfin_cf_socket *cf = from_timer(cf, t, timer); unsigned short present = bfin_cf_present(cf->cd_pfx); if (present != cf->present) { @@ -227,7 +227,7 @@ static int bfin_cf_probe(struct platform_device *pdev) cf->cd_pfx = cd_pfx; - setup_timer(&cf->timer, bfin_cf_timer, (unsigned long)cf); + timer_setup(&cf->timer, bfin_cf_timer, 0); cf->pdev = pdev; platform_set_drvdata(pdev, cf); diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c index fb38cc01859f..891ccea2cccb 100644 --- a/drivers/pcmcia/i82365.c +++ b/drivers/pcmcia/i82365.c @@ -875,7 +875,7 @@ static irqreturn_t pcic_interrupt(int irq, void *dev) return IRQ_RETVAL(handled); } /* pcic_interrupt */ -static void pcic_interrupt_wrapper(u_long data) +static void pcic_interrupt_wrapper(struct timer_list *unused) { pcic_interrupt(0, NULL); poll_timer.expires = jiffies + poll_interval; @@ -1289,9 +1289,7 @@ static int __init init_i82365(void) /* Finally, schedule a polling interrupt */ if (poll_interval != 0) { - poll_timer.function = pcic_interrupt_wrapper; - poll_timer.data = 0; - init_timer(&poll_timer); + timer_setup(&poll_timer, pcic_interrupt_wrapper, 0); poll_timer.expires = jiffies + poll_interval; add_timer(&poll_timer); } diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c index 4e2f501e5548..8216ceb51b18 100644 --- a/drivers/pcmcia/omap_cf.c +++ b/drivers/pcmcia/omap_cf.c @@ -80,9 +80,9 @@ static int omap_cf_ss_init(struct pcmcia_socket *s) } /* the timer is primarily to kick this socket's pccardd */ -static void omap_cf_timer(unsigned long _cf) +static void omap_cf_timer(struct timer_list *t) { - struct omap_cf_socket *cf = (void *) _cf; + struct omap_cf_socket *cf = from_timer(cf, t, timer); unsigned present = omap_cf_present(); if (present != cf->present) { @@ -102,7 +102,7 @@ static void omap_cf_timer(unsigned long _cf) */ static irqreturn_t omap_cf_irq(int irq, void *_cf) { - omap_cf_timer((unsigned long)_cf); + omap_cf_timer(&_cf->timer); return IRQ_HANDLED; } @@ -220,7 +220,7 @@ static int __init omap_cf_probe(struct platform_device *pdev) cf = kzalloc(sizeof *cf, GFP_KERNEL); if (!cf) return -ENOMEM; - setup_timer(&cf->timer, omap_cf_timer, (unsigned long)cf); + timer_setup(&cf->timer, omap_cf_timer, 0); cf->pdev = pdev; platform_set_drvdata(pdev, cf); diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index 0f70b4d58f9e..959ae3e65ef8 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -234,9 +234,9 @@ static irqreturn_t pd6729_interrupt(int irq, void *dev) /* socket functions */ -static void pd6729_interrupt_wrapper(unsigned long data) +static void pd6729_interrupt_wrapper(struct timer_list *t) { - struct pd6729_socket *socket = (struct pd6729_socket *) data; + struct pd6729_socket *socket = from_timer(socket, t, poll_timer); pd6729_interrupt(0, (void *)socket); mod_timer(&socket->poll_timer, jiffies + HZ); @@ -707,8 +707,7 @@ static int pd6729_pci_probe(struct pci_dev *dev, } } else { /* poll Card status change */ - setup_timer(&socket->poll_timer, pd6729_interrupt_wrapper, - (unsigned long)socket); + timer_setup(&socket->poll_timer, pd6729_interrupt_wrapper, 0); mod_timer(&socket->poll_timer, jiffies + HZ); } diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c index b6b316de055c..764650eb8897 100644 --- a/drivers/pcmcia/soc_common.c +++ b/drivers/pcmcia/soc_common.c @@ -456,9 +456,9 @@ static void soc_common_check_status(struct soc_pcmcia_socket *skt) } /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ -static void soc_common_pcmcia_poll_event(unsigned long dummy) +static void soc_common_pcmcia_poll_event(struct timer_list *t) { - struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; + struct soc_pcmcia_socket *skt = from_timer(skt, t, poll_timer); debug(skt, 4, "polling for events\n"); mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); @@ -794,8 +794,7 @@ int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt) skt->cs_state = dead_socket; - setup_timer(&skt->poll_timer, soc_common_pcmcia_poll_event, - (unsigned long)skt); + timer_setup(&skt->poll_timer, soc_common_pcmcia_poll_event, 0); skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; ret = request_resource(&iomem_resource, &skt->res_skt); diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c index a1ac72d51d70..1a0e3f098759 100644 --- a/drivers/pcmcia/tcic.c +++ b/drivers/pcmcia/tcic.c @@ -98,7 +98,7 @@ module_param(cycle_time, int, 0444); /*====================================================================*/ static irqreturn_t tcic_interrupt(int irq, void *dev); -static void tcic_timer(u_long data); +static void tcic_timer(struct timer_list *unused); static struct pccard_operations tcic_operations; struct tcic_socket { @@ -435,9 +435,7 @@ static int __init init_tcic(void) } /* Set up polling */ - poll_timer.function = &tcic_timer; - poll_timer.data = 0; - init_timer(&poll_timer); + timer_setup(&poll_timer, &tcic_timer, 0); /* Build interrupt mask */ printk(KERN_CONT ", %d sockets\n", sockets); @@ -583,7 +581,7 @@ static irqreturn_t tcic_interrupt(int irq, void *dev) return IRQ_HANDLED; } /* tcic_interrupt */ -static void tcic_timer(u_long data) +static void tcic_timer(struct timer_list *unused) { pr_debug("tcic_timer()\n"); tcic_timer_pending = 0; diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 5d6d9b1549bc..ab3da2262f0f 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -534,9 +534,9 @@ static irqreturn_t yenta_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static void yenta_interrupt_wrapper(unsigned long data) +static void yenta_interrupt_wrapper(struct timer_list *t) { - struct yenta_socket *socket = (struct yenta_socket *) data; + struct yenta_socket *socket = from_timer(socket, t, poll_timer); yenta_interrupt(0, (void *)socket); socket->poll_timer.expires = jiffies + HZ; @@ -1233,8 +1233,7 @@ static int yenta_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, IRQF_SHARED, "yenta", socket)) { /* No IRQ or request_irq failed. Poll */ socket->cb_irq = 0; /* But zero is a valid IRQ number. */ - setup_timer(&socket->poll_timer, yenta_interrupt_wrapper, - (unsigned long)socket); + timer_setup(&socket->poll_timer, yenta_interrupt_wrapper, 0); mod_timer(&socket->poll_timer, jiffies + HZ); dev_info(&dev->dev, "no PCI IRQ, CardBus support disabled for this socket.\n"); -- cgit v1.2.3-58-ga151 From c9fe0f8fa4136c2451dcc012e48fbf4470d6b592 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:00 -0700 Subject: hyper-v: trace vmbus_on_msg_dpc() Add tracing subsystem to Hyper-V VMBus module and add tracepoint to vmbus_on_msg_dpc() which is called when we receive a message from host. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/Makefile | 4 +++- drivers/hv/hv_trace.c | 4 ++++ drivers/hv/hv_trace.h | 29 +++++++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 2 ++ drivers/hv/vmbus_drv.c | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/hv_trace.c create mode 100644 drivers/hv/hv_trace.h (limited to 'drivers') diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile index 39c9b2c08d33..ad791e00230f 100644 --- a/drivers/hv/Makefile +++ b/drivers/hv/Makefile @@ -2,7 +2,9 @@ obj-$(CONFIG_HYPERV) += hv_vmbus.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o +CFLAGS_hv_trace.o = -I$(src) + hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ - channel_mgmt.o ring_buffer.o + channel_mgmt.o ring_buffer.o hv_trace.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o diff --git a/drivers/hv/hv_trace.c b/drivers/hv/hv_trace.c new file mode 100644 index 000000000000..df47acd01a81 --- /dev/null +++ b/drivers/hv/hv_trace.c @@ -0,0 +1,4 @@ +#include "hyperv_vmbus.h" + +#define CREATE_TRACE_POINTS +#include "hv_trace.h" diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h new file mode 100644 index 000000000000..9c2772922c76 --- /dev/null +++ b/drivers/hv/hv_trace.h @@ -0,0 +1,29 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM hyperv + +#if !defined(_HV_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _HV_TRACE_H + +#include + +DECLARE_EVENT_CLASS(vmbus_hdr_msg, + TP_PROTO(const struct vmbus_channel_message_header *hdr), + TP_ARGS(hdr), + TP_STRUCT__entry(__field(unsigned int, msgtype)), + TP_fast_assign(__entry->msgtype = hdr->msgtype;), + TP_printk("msgtype=%u", __entry->msgtype) +); + +DEFINE_EVENT(vmbus_hdr_msg, vmbus_on_msg_dpc, + TP_PROTO(const struct vmbus_channel_message_header *hdr), + TP_ARGS(hdr) +); + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE hv_trace +#endif /* _HV_TRACE_H */ + +/* This part must be outside protection */ +#include diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index de6f01df9592..22300ec7b556 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -31,6 +31,8 @@ #include #include +#include "hv_trace.h" + /* * Timeout for services such as KVP and fcopy. */ diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 8fe13cd76acf..8f9293a87c6b 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -835,6 +835,8 @@ void vmbus_on_msg_dpc(unsigned long data) hdr = (struct vmbus_channel_message_header *)msg->u.payload; + trace_vmbus_on_msg_dpc(hdr); + if (hdr->msgtype >= CHANNELMSG_COUNT) { WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype); goto msg_handled; -- cgit v1.2.3-58-ga151 From 716fa52fb474a36ddd3cbc981108f93610c973ef Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:01 -0700 Subject: hyper-v: trace vmbus_on_message() Add tracepoint to vmbus_on_message() which is called when we start processing a blocking from work context. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index a8dc9a164631..71d4d68488d4 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1176,6 +1176,8 @@ void vmbus_onmessage(void *context) hdr = (struct vmbus_channel_message_header *)msg->u.payload; size = msg->header.payload_size; + trace_vmbus_on_message(hdr); + if (hdr->msgtype >= CHANNELMSG_COUNT) { pr_err("Received invalid channel message type %d size %d\n", hdr->msgtype, size); diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 9c2772922c76..d432aba5df8a 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -19,6 +19,11 @@ DEFINE_EVENT(vmbus_hdr_msg, vmbus_on_msg_dpc, TP_ARGS(hdr) ); +DEFINE_EVENT(vmbus_hdr_msg, vmbus_on_message, + TP_PROTO(const struct vmbus_channel_message_header *hdr), + TP_ARGS(hdr) +); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 03b81e66c78b076bfc127714ce6fd25655784600 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:02 -0700 Subject: hyper-v: trace vmbus_onoffer() Add tracepoint to CHANNELMSG_OFFERCHANNEL handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 71d4d68488d4..7c11e17ad295 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -813,6 +813,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) offer = (struct vmbus_channel_offer_channel *)hdr; + trace_vmbus_onoffer(offer); + /* Allocate the channel object and save this offer. */ newchannel = alloc_channel(); if (!newchannel) { diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index d432aba5df8a..488b873b563e 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -24,6 +24,43 @@ DEFINE_EVENT(vmbus_hdr_msg, vmbus_on_message, TP_ARGS(hdr) ); +TRACE_EVENT(vmbus_onoffer, + TP_PROTO(const struct vmbus_channel_offer_channel *offer), + TP_ARGS(offer), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u8, monitorid) + __field(u16, is_ddc_int) + __field(u32, connection_id) + __array(char, if_type, 16) + __array(char, if_instance, 16) + __field(u16, chn_flags) + __field(u16, mmio_mb) + __field(u16, sub_idx) + ), + TP_fast_assign(__entry->child_relid = offer->child_relid; + __entry->monitorid = offer->monitorid; + __entry->is_ddc_int = offer->is_dedicated_interrupt; + __entry->connection_id = offer->connection_id; + memcpy(__entry->if_type, + &offer->offer.if_type.b, 16); + memcpy(__entry->if_instance, + &offer->offer.if_instance.b, 16); + __entry->chn_flags = offer->offer.chn_flags; + __entry->mmio_mb = offer->offer.mmio_megabytes; + __entry->sub_idx = offer->offer.sub_channel_index; + ), + TP_printk("child_relid 0x%x, monitorid 0x%x, is_dedicated %d, " + "connection_id 0x%x, if_type %pUl, if_instance %pUl, " + "chn_flags 0x%x, mmio_megabytes %d, sub_channel_index %d", + __entry->child_relid, __entry->monitorid, + __entry->is_ddc_int, __entry->connection_id, + __entry->if_type, __entry->if_instance, + __entry->chn_flags, __entry->mmio_mb, + __entry->sub_idx + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 5175167c77afb19993bd86ab8b4be63d9cb4a928 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:03 -0700 Subject: hyper-v: trace vmbus_onoffer_rescind() Add tracepoint to CHANNELMSG_RESCIND_CHANNELOFFER handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 7c11e17ad295..cfe5c9c6a87c 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -856,6 +856,8 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) rescind = (struct vmbus_channel_rescind_offer *)hdr; + trace_vmbus_onoffer_rescind(rescind); + /* * The offer msg and the corresponding rescind msg * from the host are guranteed to be ordered - diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 488b873b563e..dbbed1d1f327 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -61,6 +61,14 @@ TRACE_EVENT(vmbus_onoffer, ) ); +TRACE_EVENT(vmbus_onoffer_rescind, + TP_PROTO(const struct vmbus_channel_rescind_offer *offer), + TP_ARGS(offer), + TP_STRUCT__entry(__field(u32, child_relid)), + TP_fast_assign(__entry->child_relid = offer->child_relid), + TP_printk("child_relid 0x%x", __entry->child_relid) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 9f23ce1a23b6bf471d5920bdca5cc40940419e60 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:04 -0700 Subject: hyper-v: trace vmbus_onopen_result() Add tracepoint to CHANNELMSG_OPENCHANNEL_RESULT handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index cfe5c9c6a87c..c735abe01712 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -986,6 +986,8 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) result = (struct vmbus_channel_open_result *)hdr; + trace_vmbus_onopen_result(result); + /* * Find the open msg, copy the result and signal/unblock the wait event */ diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index dbbed1d1f327..9757c19d1c08 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -69,6 +69,23 @@ TRACE_EVENT(vmbus_onoffer_rescind, TP_printk("child_relid 0x%x", __entry->child_relid) ); +TRACE_EVENT(vmbus_onopen_result, + TP_PROTO(const struct vmbus_channel_open_result *result), + TP_ARGS(result), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u32, openid) + __field(u32, status) + ), + TP_fast_assign(__entry->child_relid = result->child_relid; + __entry->openid = result->openid; + __entry->status = result->status; + ), + TP_printk("child_relid 0x%x, openid %d, status %d", + __entry->child_relid, __entry->openid, __entry->status + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From a13bf0ea4a60a7946bf335bd57e60adc344033bd Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:05 -0700 Subject: hyper-v: trace vmbus_ongpadl_created() Add tracepoint to CHANNELMSG_GPADL_CREATED handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index c735abe01712..4bff75449afb 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1032,6 +1032,8 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; + trace_vmbus_ongpadl_created(gpadlcreated); + /* * Find the establish msg, copy the result and signal/unblock the wait * event diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 9757c19d1c08..20734b7b341b 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -86,6 +86,23 @@ TRACE_EVENT(vmbus_onopen_result, ) ); +TRACE_EVENT(vmbus_ongpadl_created, + TP_PROTO(const struct vmbus_channel_gpadl_created *gpadlcreated), + TP_ARGS(gpadlcreated), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u32, gpadl) + __field(u32, status) + ), + TP_fast_assign(__entry->child_relid = gpadlcreated->child_relid; + __entry->gpadl = gpadlcreated->gpadl; + __entry->status = gpadlcreated->creation_status; + ), + TP_printk("child_relid 0x%x, gpadl 0x%x, creation_status %d", + __entry->child_relid, __entry->gpadl, __entry->status + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 602a8c525c8c7b2ff446894fc6b21f42471c952f Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:06 -0700 Subject: hyper-v: trace vmbus_ongpadl_torndown() Add tracepoint to CHANNELMSG_GPADL_TORNDOWN handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 2 ++ drivers/hv/hv_trace.h | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 4bff75449afb..d1cb85257bf0 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1082,6 +1082,8 @@ static void vmbus_ongpadl_torndown( gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr; + trace_vmbus_ongpadl_torndown(gpadl_torndown); + /* * Find the open msg, copy the result and signal/unblock the wait event */ diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 20734b7b341b..84c08cdf7235 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -103,6 +103,14 @@ TRACE_EVENT(vmbus_ongpadl_created, ) ); +TRACE_EVENT(vmbus_ongpadl_torndown, + TP_PROTO(const struct vmbus_channel_gpadl_torndown *gpadltorndown), + TP_ARGS(gpadltorndown), + TP_STRUCT__entry(__field(u32, gpadl)), + TP_fast_assign(__entry->gpadl = gpadltorndown->gpadl), + TP_printk("gpadl 0x%x", __entry->gpadl) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From c7924fb07a2646c9ff661efcad1167a1106d6019 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:07 -0700 Subject: hyper-v: trace vmbus_onversion_response() Add tracepoint to CHANNELMSG_VERSION_RESPONSE handler. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 3 +++ drivers/hv/hv_trace.h | 11 +++++++++++ 2 files changed, 14 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index d1cb85257bf0..c33b7412f303 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1127,6 +1127,9 @@ static void vmbus_onversion_response( unsigned long flags; version_response = (struct vmbus_channel_version_response *)hdr; + + trace_vmbus_onversion_response(version_response); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 84c08cdf7235..2a046547107f 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -111,6 +111,17 @@ TRACE_EVENT(vmbus_ongpadl_torndown, TP_printk("gpadl 0x%x", __entry->gpadl) ); +TRACE_EVENT(vmbus_onversion_response, + TP_PROTO(const struct vmbus_channel_version_response *response), + TP_ARGS(response), + TP_STRUCT__entry( + __field(u8, ver) + ), + TP_fast_assign(__entry->ver = response->version_supported; + ), + TP_printk("version_supported %d", __entry->ver) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From d6706e63367a9c783974db4b94cf8980d31c4cb2 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:08 -0700 Subject: hyper-v: trace vmbus_request_offers() Add tracepoint to CHANNELMSG_REQUESTOFFERS sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 4 +++- drivers/hv/hv_trace.h | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index c33b7412f303..b27edff8796e 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1224,9 +1224,11 @@ int vmbus_request_offers(void) msg->msgtype = CHANNELMSG_REQUESTOFFERS; - ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_message_header), true); + + trace_vmbus_request_offers(ret); + if (ret != 0) { pr_err("Unable to request offers - %d\n", ret); diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 2a046547107f..566ac0f2fe56 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -122,6 +122,14 @@ TRACE_EVENT(vmbus_onversion_response, TP_printk("version_supported %d", __entry->ver) ); +TRACE_EVENT(vmbus_request_offers, + TP_PROTO(int ret), + TP_ARGS(ret), + TP_STRUCT__entry(__field(int, ret)), + TP_fast_assign(__entry->ret = ret), + TP_printk("sending ret %d", __entry->ret) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 9202d771ca37514bfbc2c3a8fdcb018f40a6bd8a Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:09 -0700 Subject: hyper-v: trace vmbus_open() Add tracepoint to CHANNELMSG_OPENCHANNEL sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 2 ++ drivers/hv/hv_trace.h | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index a406beb10dd0..739b3fe1e0fb 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -185,6 +185,8 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ret = vmbus_post_msg(open_msg, sizeof(struct vmbus_channel_open_channel), true); + trace_vmbus_open(open_msg, ret); + if (ret != 0) { err = ret; goto error_clean_msglist; diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 566ac0f2fe56..38fedb803bd8 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -130,6 +130,33 @@ TRACE_EVENT(vmbus_request_offers, TP_printk("sending ret %d", __entry->ret) ); +TRACE_EVENT(vmbus_open, + TP_PROTO(const struct vmbus_channel_open_channel *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u32, openid) + __field(u32, gpadlhandle) + __field(u32, target_vp) + __field(u32, offset) + __field(int, ret) + ), + TP_fast_assign( + __entry->child_relid = msg->child_relid; + __entry->openid = msg->openid; + __entry->gpadlhandle = msg->ringbuffer_gpadlhandle; + __entry->target_vp = msg->target_vp; + __entry->offset = msg->downstream_ringbuffer_pageoffset; + __entry->ret = ret; + ), + TP_printk("sending child_relid 0x%x, openid %d, " + "gpadlhandle 0x%x, target_vp 0x%x, offset 0x%x, ret %d", + __entry->child_relid, __entry->openid, + __entry->gpadlhandle, __entry->target_vp, + __entry->offset, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 633b005df0dff555c0d4f22b5f1f8b04dba67ac5 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:10 -0700 Subject: hyper-v: trace vmbus_close_internal() Add tracepoint to CHANNELMSG_CLOSECHANNEL sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 2 ++ drivers/hv/hv_trace.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 739b3fe1e0fb..a827f43aa408 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -591,6 +591,8 @@ static int vmbus_close_internal(struct vmbus_channel *channel) ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_close_channel), true); + trace_vmbus_close_internal(msg, ret); + if (ret) { pr_err("Close failed: close post msg return is %d\n", ret); /* diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 38fedb803bd8..302bd4e964f0 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -157,6 +157,21 @@ TRACE_EVENT(vmbus_open, ) ); +TRACE_EVENT(vmbus_close_internal, + TP_PROTO(const struct vmbus_channel_close_channel *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(int, ret) + ), + TP_fast_assign( + __entry->child_relid = msg->child_relid; + __entry->ret = ret; + ), + TP_printk("sending child_relid 0x%x, ret %d", __entry->child_relid, + __entry->ret) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 69edbd5f4729a58e11437b2804103bf8ea52745c Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:11 -0700 Subject: hyper-v: trace vmbus_establish_gpadl() Add tracepoint to CHANNELMSG_GPADL_HEADER/CHANNELMSG_GPADL_BODY sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 6 ++++++ drivers/hv/hv_trace.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index a827f43aa408..823ddc714d56 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -435,6 +435,9 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - sizeof(*msginfo), true); + + trace_vmbus_establish_gpadl_header(gpadlmsg, ret); + if (ret != 0) goto cleanup; @@ -450,6 +453,9 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ret = vmbus_post_msg(gpadl_body, submsginfo->msgsize - sizeof(*submsginfo), true); + + trace_vmbus_establish_gpadl_body(gpadl_body, ret); + if (ret != 0) goto cleanup; diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 302bd4e964f0..978e70bdc7c5 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -172,6 +172,48 @@ TRACE_EVENT(vmbus_close_internal, __entry->ret) ); +TRACE_EVENT(vmbus_establish_gpadl_header, + TP_PROTO(const struct vmbus_channel_gpadl_header *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u32, gpadl) + __field(u16, range_buflen) + __field(u16, rangecount) + __field(int, ret) + ), + TP_fast_assign( + __entry->child_relid = msg->child_relid; + __entry->gpadl = msg->gpadl; + __entry->range_buflen = msg->range_buflen; + __entry->rangecount = msg->rangecount; + __entry->ret = ret; + ), + TP_printk("sending child_relid 0x%x, gpadl 0x%x, range_buflen %d " + "rangecount %d, ret %d", + __entry->child_relid, __entry->gpadl, + __entry->range_buflen, __entry->rangecount, __entry->ret + ) + ); + +TRACE_EVENT(vmbus_establish_gpadl_body, + TP_PROTO(const struct vmbus_channel_gpadl_body *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, msgnumber) + __field(u32, gpadl) + __field(int, ret) + ), + TP_fast_assign( + __entry->msgnumber = msg->msgnumber; + __entry->gpadl = msg->gpadl; + __entry->ret = ret; + ), + TP_printk("sending msgnumber %d, gpadl 0x%x, ret %d", + __entry->msgnumber, __entry->gpadl, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 09cdf8f87c15dbe9a3eeb6de04aaafd0cd922d6d Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:12 -0700 Subject: hyper-v: trace vmbus_teardown_gpadl() Add tracepoint to CHANNELMSG_GPADL_TEARDOWN sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 2 ++ drivers/hv/hv_trace.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 823ddc714d56..0382d7b600a1 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -519,6 +519,8 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_gpadl_teardown), true); + trace_vmbus_teardown_gpadl(msg, ret); + if (ret) goto post_msg_err; diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 978e70bdc7c5..cd33a52ef27f 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -214,6 +214,24 @@ TRACE_EVENT(vmbus_establish_gpadl_body, ) ); +TRACE_EVENT(vmbus_teardown_gpadl, + TP_PROTO(const struct vmbus_channel_gpadl_teardown *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(u32, gpadl) + __field(int, ret) + ), + TP_fast_assign( + __entry->child_relid = msg->child_relid; + __entry->gpadl = msg->gpadl; + __entry->ret = ret; + ), + TP_printk("sending child_relid 0x%x, gpadl 0x%x, ret %d", + __entry->child_relid, __entry->gpadl, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 034ebf552e0a3403eeb7e7f8a3a502fc0c70a24c Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:13 -0700 Subject: hyper-v: trace vmbus_negotiate_version() Add tracepoint to CHANNELMSG_INITIATE_CONTACT sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/connection.c | 3 +++ drivers/hv/hv_trace.h | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index b06a6b796819..05f413c4fe3b 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -117,6 +117,9 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_initiate_contact), true); + + trace_vmbus_negotiate_version(msg, ret); + if (ret != 0) { spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&msginfo->msglistentry); diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index cd33a52ef27f..f06284d64a8c 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -232,6 +232,32 @@ TRACE_EVENT(vmbus_teardown_gpadl, ) ); +TRACE_EVENT(vmbus_negotiate_version, + TP_PROTO(const struct vmbus_channel_initiate_contact *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, ver) + __field(u32, target_vcpu) + __field(int, ret) + __field(u64, int_page) + __field(u64, mon_page1) + __field(u64, mon_page2) + ), + TP_fast_assign( + __entry->ver = msg->vmbus_version_requested; + __entry->target_vcpu = msg->target_vcpu; + __entry->int_page = msg->interrupt_page; + __entry->mon_page1 = msg->monitor_page1; + __entry->mon_page2 = msg->monitor_page2; + __entry->ret = ret; + ), + TP_printk("sending vmbus_version_requested %d, target_vcpu 0x%x, " + "pages %llx:%llx:%llx, ret %d", + __entry->ver, __entry->target_vcpu, __entry->int_page, + __entry->mon_page1, __entry->mon_page2, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 259cc665e9c08d054549a877c1b53b793de15753 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:14 -0700 Subject: hyper-v: trace vmbus_release_relid() Add tracepoint to CHANNELMSG_RELID_RELEASED sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 7 +++++-- drivers/hv/hv_trace.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index b27edff8796e..ec5454f3f4a6 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -373,12 +373,15 @@ static void percpu_channel_deq(void *arg) static void vmbus_release_relid(u32 relid) { struct vmbus_channel_relid_released msg; + int ret; memset(&msg, 0, sizeof(struct vmbus_channel_relid_released)); msg.child_relid = relid; msg.header.msgtype = CHANNELMSG_RELID_RELEASED; - vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released), - true); + ret = vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released), + true); + + trace_vmbus_release_relid(&msg, ret); } void hv_process_channel_removal(u32 relid) diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index f06284d64a8c..f0e437c3522f 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -258,6 +258,22 @@ TRACE_EVENT(vmbus_negotiate_version, ) ); +TRACE_EVENT(vmbus_release_relid, + TP_PROTO(const struct vmbus_channel_relid_released *msg, int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __field(u32, child_relid) + __field(int, ret) + ), + TP_fast_assign( + __entry->child_relid = msg->child_relid; + __entry->ret = ret; + ), + TP_printk("sending child_relid 0x%x, ret %d", + __entry->child_relid, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 98f31a0050ca8ba47b57c6d67599013cdbdd2122 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:15 -0700 Subject: hyper-v: trace vmbus_send_tl_connect_request() Add tracepoint to CHANNELMSG_TL_CONNECT_REQUEST sender. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 7 ++++++- drivers/hv/hv_trace.h | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 0382d7b600a1..ed3634e53e15 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -236,13 +236,18 @@ int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id, const uuid_le *shv_host_servie_id) { struct vmbus_channel_tl_connect_request conn_msg; + int ret; memset(&conn_msg, 0, sizeof(conn_msg)); conn_msg.header.msgtype = CHANNELMSG_TL_CONNECT_REQUEST; conn_msg.guest_endpoint_id = *shv_guest_servie_id; conn_msg.host_service_id = *shv_host_servie_id; - return vmbus_post_msg(&conn_msg, sizeof(conn_msg), true); + ret = vmbus_post_msg(&conn_msg, sizeof(conn_msg), true); + + trace_vmbus_send_tl_connect_request(&conn_msg, ret); + + return ret; } EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request); diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index f0e437c3522f..5382d9630306 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -274,6 +274,26 @@ TRACE_EVENT(vmbus_release_relid, ) ); +TRACE_EVENT(vmbus_send_tl_connect_request, + TP_PROTO(const struct vmbus_channel_tl_connect_request *msg, + int ret), + TP_ARGS(msg, ret), + TP_STRUCT__entry( + __array(char, guest_id, 16) + __array(char, host_id, 16) + __field(int, ret) + ), + TP_fast_assign( + memcpy(__entry->guest_id, &msg->guest_endpoint_id.b, 16); + memcpy(__entry->host_id, &msg->host_service_id.b, 16); + __entry->ret = ret; + ), + TP_printk("sending guest_endpoint_id %pUl, host_service_id %pUl, " + "ret %d", + __entry->guest_id, __entry->host_id, __entry->ret + ) + ); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE -- cgit v1.2.3-58-ga151 From 991f8f1c6eb634688952fa6a03cc0ce949b6e363 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sun, 29 Oct 2017 12:21:16 -0700 Subject: hyper-v: trace channel events Added an additional set of trace points for when channel gets notified or signals host. Suggested-by: Stephen Hemminger Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel.c | 2 ++ drivers/hv/connection.c | 2 ++ drivers/hv/hv_trace.h | 23 +++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 2 ++ 4 files changed, 29 insertions(+) (limited to 'drivers') diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index ed3634e53e15..19f0cf37e0ed 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -43,6 +43,8 @@ void vmbus_setevent(struct vmbus_channel *channel) { struct hv_monitor_page *monitorpage; + trace_vmbus_setevent(channel); + /* * For channels marked as in "low latency" mode * bypass the monitor page mechanism. diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 05f413c4fe3b..447371f4de56 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -322,6 +322,8 @@ void vmbus_on_event(unsigned long data) struct vmbus_channel *channel = (void *) data; unsigned long time_limit = jiffies + 2; + trace_vmbus_on_event(channel); + do { void (*callback_fn)(void *); diff --git a/drivers/hv/hv_trace.h b/drivers/hv/hv_trace.h index 5382d9630306..d635ee95b20d 100644 --- a/drivers/hv/hv_trace.h +++ b/drivers/hv/hv_trace.h @@ -294,6 +294,29 @@ TRACE_EVENT(vmbus_send_tl_connect_request, ) ); +DECLARE_EVENT_CLASS(vmbus_channel, + TP_PROTO(const struct vmbus_channel *channel), + TP_ARGS(channel), + TP_STRUCT__entry(__field(u32, relid)), + TP_fast_assign(__entry->relid = channel->offermsg.child_relid), + TP_printk("relid 0x%x", __entry->relid) +); + +DEFINE_EVENT(vmbus_channel, vmbus_chan_sched, + TP_PROTO(const struct vmbus_channel *channel), + TP_ARGS(channel) +); + +DEFINE_EVENT(vmbus_channel, vmbus_setevent, + TP_PROTO(const struct vmbus_channel *channel), + TP_ARGS(channel) +); + +DEFINE_EVENT(vmbus_channel, vmbus_on_event, + TP_PROTO(const struct vmbus_channel *channel), + TP_ARGS(channel) +); + #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #undef TRACE_INCLUDE_FILE diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 8f9293a87c6b..6a86746d4f60 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -946,6 +946,8 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) if (channel->rescind) continue; + trace_vmbus_chan_sched(channel); + ++channel->interrupts; switch (channel->callback_mode) { -- cgit v1.2.3-58-ga151 From e9c16affe064c84cdccbe96d9896fe149602bceb Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Sat, 4 Nov 2017 19:36:43 -0700 Subject: drivers/pcmcia: omap1: Fix error in automated timer conversion One part of automated timer conversion tools did not take into account void * variables when searching out prior direct timer callback usage, which resulted in an attempt to dereference the timer field without a proper type. Reported-by: kbuild test robot Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/omap_cf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c index 8216ceb51b18..c2a17a79f0b2 100644 --- a/drivers/pcmcia/omap_cf.c +++ b/drivers/pcmcia/omap_cf.c @@ -102,7 +102,9 @@ static void omap_cf_timer(struct timer_list *t) */ static irqreturn_t omap_cf_irq(int irq, void *_cf) { - omap_cf_timer(&_cf->timer); + struct omap_cf_socket *cf = (struct omap_cf_socket *)_cf; + + omap_cf_timer(&cf->timer); return IRQ_HANDLED; } -- cgit v1.2.3-58-ga151 From a2e373438f72391493a4425efc1b82030b6b4fd5 Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Sat, 4 Nov 2017 23:52:54 -0500 Subject: thunderbolt: tb: fix use after free in tb_activate_pcie_devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a ̣̣continue statement in order to avoid using a previously free'd pointer tunnel in list_add. Addresses-Coverity-ID: 1415336 Fixes: 9d3cce0b6136 ("thunderbolt: Introduce thunderbolt bus and connection manager") Signed-off-by: Gustavo A. R. Silva Acked-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/tb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 0b22ad9d68b4..f7d0c60c6a11 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -224,6 +224,7 @@ static void tb_activate_pcie_devices(struct tb *tb) tb_port_info(up_port, "PCIe tunnel activation failed, aborting\n"); tb_pci_free(tunnel); + continue; } list_add(&tunnel->list, &tcm->tunnel_list); -- cgit v1.2.3-58-ga151 From 01d35cabd5abda28c352f63c87109c477fc84886 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 21 Oct 2017 01:57:38 +0900 Subject: nvmem: imx-iim: use stack for nvmem_config instead of malloc'ing it nvmem_register() copies all the members of nvmem_config to nvmem_device. So, nvmem_config is one-time use data during probing. There is no point to keep it until the driver detach. Using stack should be no problem because nvmem_config is pretty small. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-iim.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-iim.c b/drivers/nvmem/imx-iim.c index 52ff65e0673f..a5992602709a 100644 --- a/drivers/nvmem/imx-iim.c +++ b/drivers/nvmem/imx-iim.c @@ -34,7 +34,6 @@ struct imx_iim_drvdata { struct iim_priv { void __iomem *base; struct clk *clk; - struct nvmem_config nvmem; }; static int imx_iim_read(void *context, unsigned int offset, @@ -108,7 +107,7 @@ static int imx_iim_probe(struct platform_device *pdev) struct resource *res; struct iim_priv *iim; struct nvmem_device *nvmem; - struct nvmem_config *cfg; + struct nvmem_config cfg = {}; const struct imx_iim_drvdata *drvdata = NULL; iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL); @@ -130,19 +129,17 @@ static int imx_iim_probe(struct platform_device *pdev) if (IS_ERR(iim->clk)) return PTR_ERR(iim->clk); - cfg = &iim->nvmem; - - cfg->name = "imx-iim", - cfg->read_only = true, - cfg->word_size = 1, - cfg->stride = 1, - cfg->owner = THIS_MODULE, - cfg->reg_read = imx_iim_read, - cfg->dev = dev; - cfg->size = drvdata->nregs; - cfg->priv = iim; - - nvmem = nvmem_register(cfg); + cfg.name = "imx-iim", + cfg.read_only = true, + cfg.word_size = 1, + cfg.stride = 1, + cfg.owner = THIS_MODULE, + cfg.reg_read = imx_iim_read, + cfg.dev = dev; + cfg.size = drvdata->nregs; + cfg.priv = iim; + + nvmem = nvmem_register(&cfg); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); -- cgit v1.2.3-58-ga151 From 4dd5f60e9a841da5c14c2a0a23290adddb4b5087 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 21 Oct 2017 01:57:39 +0900 Subject: nvmem: mtk-efuse: use stack for nvmem_config instead of malloc'ing it nvmem_register() copies all the members of nvmem_config to nvmem_device. So, nvmem_config is one-time use data during probing. There is no point to keep it until the driver detach. Using stack should be no problem because nvmem_config is pretty small. Signed-off-by: Masahiro Yamada Acked-by: Sean Wang Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/mtk-efuse.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index 32fd572e18c5..fa7a0f66b37e 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -49,7 +49,7 @@ static int mtk_efuse_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct resource *res; struct nvmem_device *nvmem; - struct nvmem_config *econfig; + struct nvmem_config econfig = {}; void __iomem *base; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -57,19 +57,15 @@ static int mtk_efuse_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); - if (!econfig) - return -ENOMEM; - - econfig->stride = 4; - econfig->word_size = 4; - econfig->reg_read = mtk_reg_read; - econfig->reg_write = mtk_reg_write; - econfig->size = resource_size(res); - econfig->priv = base; - econfig->dev = dev; - econfig->owner = THIS_MODULE; - nvmem = nvmem_register(econfig); + econfig.stride = 4; + econfig.word_size = 4; + econfig.reg_read = mtk_reg_read; + econfig.reg_write = mtk_reg_write; + econfig.size = resource_size(res); + econfig.priv = base; + econfig.dev = dev; + econfig.owner = THIS_MODULE; + nvmem = nvmem_register(&econfig); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); -- cgit v1.2.3-58-ga151 From a48f1fff7e2fe5fbaf0295ff7705909fd31f1c35 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 21 Oct 2017 01:57:40 +0900 Subject: nvmem: mtk-efuse: fix different address space warnings of sparse Fix the following sparse warnings: drivers/nvmem/mtk-efuse.c:24:30: warning: incorrect type in initializer (different address spaces) drivers/nvmem/mtk-efuse.c:24:30: expected void [noderef] *base drivers/nvmem/mtk-efuse.c:24:30: got void *context drivers/nvmem/mtk-efuse.c:37:30: warning: incorrect type in initializer (different address spaces) drivers/nvmem/mtk-efuse.c:37:30: expected void [noderef] *base drivers/nvmem/mtk-efuse.c:37:30: got void *context drivers/nvmem/mtk-efuse.c:69:23: warning: incorrect type in assignment (different address spaces) drivers/nvmem/mtk-efuse.c:69:23: expected void *priv drivers/nvmem/mtk-efuse.c:69:23: got void [noderef] *[assigned] base The type of nvmem_config->priv is (void *), so sparse complains about assignment of the base address with (void __iomem *) type. Even if we cast it out, sparse still warns: warning: cast removes address space of expression Of course, we can shut up the sparse by marking __force, but a more correct way is to put the base address into driver private data. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/mtk-efuse.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index fa7a0f66b37e..c4058b598703 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -18,15 +18,19 @@ #include #include +struct mtk_efuse_priv { + void __iomem *base; +}; + static int mtk_reg_read(void *context, unsigned int reg, void *_val, size_t bytes) { - void __iomem *base = context; + struct mtk_efuse_priv *priv = context; u32 *val = _val; int i = 0, words = bytes / 4; while (words--) - *val++ = readl(base + reg + (i++ * 4)); + *val++ = readl(priv->base + reg + (i++ * 4)); return 0; } @@ -34,12 +38,12 @@ static int mtk_reg_read(void *context, static int mtk_reg_write(void *context, unsigned int reg, void *_val, size_t bytes) { - void __iomem *base = context; + struct mtk_efuse_priv *priv = context; u32 *val = _val; int i = 0, words = bytes / 4; while (words--) - writel(*val++, base + reg + (i++ * 4)); + writel(*val++, priv->base + reg + (i++ * 4)); return 0; } @@ -50,19 +54,23 @@ static int mtk_efuse_probe(struct platform_device *pdev) struct resource *res; struct nvmem_device *nvmem; struct nvmem_config econfig = {}; - void __iomem *base; + struct mtk_efuse_priv *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base = devm_ioremap_resource(dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + priv->base = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); econfig.stride = 4; econfig.word_size = 4; econfig.reg_read = mtk_reg_read; econfig.reg_write = mtk_reg_write; econfig.size = resource_size(res); - econfig.priv = base; + econfig.priv = priv; econfig.dev = dev; econfig.owner = THIS_MODULE; nvmem = nvmem_register(&econfig); -- cgit v1.2.3-58-ga151 From ec3672b81fc8ff490e478bc5124f68c2be7174ee Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 21 Oct 2017 01:57:41 +0900 Subject: nvmem: qfprom: fix different address space warnings of sparse Fix the following sparse warnings: drivers/nvmem/qfprom.c:23:30: warning: incorrect type in initializer (different address spaces) drivers/nvmem/qfprom.c:23:30: expected void [noderef] *base drivers/nvmem/qfprom.c:23:30: got void *context drivers/nvmem/qfprom.c:36:30: warning: incorrect type in initializer (different address spaces) drivers/nvmem/qfprom.c:36:30: expected void [noderef] *base drivers/nvmem/qfprom.c:36:30: got void *context drivers/nvmem/qfprom.c:76:22: warning: incorrect type in assignment (different address spaces) drivers/nvmem/qfprom.c:76:22: expected void *static [toplevel] [assigned] priv drivers/nvmem/qfprom.c:76:22: got void [noderef] *[assigned] base The type of nvmem_config->priv is (void *), so sparse complains about assignment of the base address with (void __iomem *) type. Even if we cast it out, sparse still warns: warning: cast removes address space of expression Of course, we can shut up the sparse by marking __force, but a more correct way is to put the base address into driver private data. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/qfprom.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index 2bdb6c389328..b96730e99580 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c @@ -17,15 +17,19 @@ #include #include +struct qfprom_priv { + void __iomem *base; +}; + static int qfprom_reg_read(void *context, unsigned int reg, void *_val, size_t bytes) { - void __iomem *base = context; + struct qfprom_priv *priv = context; u8 *val = _val; int i = 0, words = bytes; while (words--) - *val++ = readb(base + reg + i++); + *val++ = readb(priv->base + reg + i++); return 0; } @@ -33,12 +37,12 @@ static int qfprom_reg_read(void *context, static int qfprom_reg_write(void *context, unsigned int reg, void *_val, size_t bytes) { - void __iomem *base = context; + struct qfprom_priv *priv = context; u8 *val = _val; int i = 0, words = bytes; while (words--) - writeb(*val++, base + reg + i++); + writeb(*val++, priv->base + reg + i++); return 0; } @@ -64,16 +68,20 @@ static int qfprom_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct resource *res; struct nvmem_device *nvmem; - void __iomem *base; + struct qfprom_priv *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base = devm_ioremap_resource(dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + priv->base = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); econfig.size = resource_size(res); econfig.dev = dev; - econfig.priv = base; + econfig.priv = priv; nvmem = nvmem_register(&econfig); if (IS_ERR(nvmem)) -- cgit v1.2.3-58-ga151 From 17eb18d674d586e609a3e268975edd728d5c84a3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 21 Oct 2017 01:57:42 +0900 Subject: nvmem: set nvmem->owner to nvmem->dev->driver->owner if unset All nvmem drivers are supposed to set the owner field of struct nvmem_config, but this matches nvmem->dev->driver->owner. As far as I see in drivers/nvmem/ directory, all the drivers are the case. So, make nvmem_register() set the nvmem's owner to the associated driver's owner unless nvmem_config sets otherwise. Remove .owner settings in the drivers that are now redundant. Signed-off-by: Masahiro Yamada Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/bcm-ocotp.c | 1 - drivers/nvmem/core.c | 2 ++ drivers/nvmem/imx-iim.c | 1 - drivers/nvmem/imx-ocotp.c | 1 - drivers/nvmem/lpc18xx_eeprom.c | 1 - drivers/nvmem/lpc18xx_otp.c | 1 - drivers/nvmem/meson-efuse.c | 1 - drivers/nvmem/mtk-efuse.c | 1 - drivers/nvmem/mxs-ocotp.c | 1 - drivers/nvmem/qfprom.c | 1 - drivers/nvmem/rockchip-efuse.c | 1 - drivers/nvmem/sunxi_sid.c | 1 - drivers/nvmem/vf610-ocotp.c | 1 - 13 files changed, 2 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/bcm-ocotp.c b/drivers/nvmem/bcm-ocotp.c index 3c56e3b2bd65..5e9e324427f9 100644 --- a/drivers/nvmem/bcm-ocotp.c +++ b/drivers/nvmem/bcm-ocotp.c @@ -232,7 +232,6 @@ static struct nvmem_config bcm_otpc_nvmem_config = { .read_only = false, .word_size = 4, .stride = 4, - .owner = THIS_MODULE, .reg_read = bcm_otpc_read, .reg_write = bcm_otpc_write, }; diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 864904594063..5a5cefd12153 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -462,6 +462,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->id = rval; nvmem->owner = config->owner; + if (!nvmem->owner && config->dev->driver) + nvmem->owner = config->dev->driver->owner; nvmem->stride = config->stride; nvmem->word_size = config->word_size; nvmem->size = config->size; diff --git a/drivers/nvmem/imx-iim.c b/drivers/nvmem/imx-iim.c index a5992602709a..52cfe91d9762 100644 --- a/drivers/nvmem/imx-iim.c +++ b/drivers/nvmem/imx-iim.c @@ -133,7 +133,6 @@ static int imx_iim_probe(struct platform_device *pdev) cfg.read_only = true, cfg.word_size = 1, cfg.stride = 1, - cfg.owner = THIS_MODULE, cfg.reg_read = imx_iim_read, cfg.dev = dev; cfg.size = drvdata->nregs; diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 193ca8fd350a..e57e2a57aa3f 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -303,7 +303,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .read_only = false, .word_size = 4, .stride = 4, - .owner = THIS_MODULE, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, }; diff --git a/drivers/nvmem/lpc18xx_eeprom.c b/drivers/nvmem/lpc18xx_eeprom.c index 6c7e2c424a4e..b1af966206a6 100644 --- a/drivers/nvmem/lpc18xx_eeprom.c +++ b/drivers/nvmem/lpc18xx_eeprom.c @@ -159,7 +159,6 @@ static struct nvmem_config lpc18xx_nvmem_config = { .word_size = 4, .reg_read = lpc18xx_eeprom_read, .reg_write = lpc18xx_eeprom_gather_write, - .owner = THIS_MODULE, }; static int lpc18xx_eeprom_probe(struct platform_device *pdev) diff --git a/drivers/nvmem/lpc18xx_otp.c b/drivers/nvmem/lpc18xx_otp.c index be8d07403ffc..95268db155e9 100644 --- a/drivers/nvmem/lpc18xx_otp.c +++ b/drivers/nvmem/lpc18xx_otp.c @@ -64,7 +64,6 @@ static struct nvmem_config lpc18xx_otp_nvmem_config = { .read_only = true, .word_size = LPC18XX_OTP_WORD_SIZE, .stride = LPC18XX_OTP_WORD_SIZE, - .owner = THIS_MODULE, .reg_read = lpc18xx_otp_read, }; diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c index 1ea3cd24a508..a43c68f90937 100644 --- a/drivers/nvmem/meson-efuse.c +++ b/drivers/nvmem/meson-efuse.c @@ -37,7 +37,6 @@ static int meson_efuse_read(void *context, unsigned int offset, static struct nvmem_config econfig = { .name = "meson-efuse", - .owner = THIS_MODULE, .stride = 1, .word_size = 1, .read_only = true, diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index c4058b598703..9ee3479cfc7b 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -72,7 +72,6 @@ static int mtk_efuse_probe(struct platform_device *pdev) econfig.size = resource_size(res); econfig.priv = priv; econfig.dev = dev; - econfig.owner = THIS_MODULE; nvmem = nvmem_register(&econfig); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); diff --git a/drivers/nvmem/mxs-ocotp.c b/drivers/nvmem/mxs-ocotp.c index d26dd03cec80..7018e2ef5714 100644 --- a/drivers/nvmem/mxs-ocotp.c +++ b/drivers/nvmem/mxs-ocotp.c @@ -118,7 +118,6 @@ static struct nvmem_config ocotp_config = { .name = "mxs-ocotp", .stride = 16, .word_size = 4, - .owner = THIS_MODULE, .reg_read = mxs_ocotp_read, }; diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index b96730e99580..cb3b48b47d64 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c @@ -56,7 +56,6 @@ static int qfprom_remove(struct platform_device *pdev) static struct nvmem_config econfig = { .name = "qfprom", - .owner = THIS_MODULE, .stride = 1, .word_size = 1, .reg_read = qfprom_reg_read, diff --git a/drivers/nvmem/rockchip-efuse.c b/drivers/nvmem/rockchip-efuse.c index eb4c530c2564..123de77ca5d6 100644 --- a/drivers/nvmem/rockchip-efuse.c +++ b/drivers/nvmem/rockchip-efuse.c @@ -149,7 +149,6 @@ static int rockchip_rk3399_efuse_read(void *context, unsigned int offset, static struct nvmem_config econfig = { .name = "rockchip-efuse", - .owner = THIS_MODULE, .stride = 1, .word_size = 1, .read_only = true, diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 0d6648be93b8..1c3b5cf89212 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -40,7 +40,6 @@ static struct nvmem_config econfig = { .read_only = true, .stride = 4, .word_size = 1, - .owner = THIS_MODULE, }; struct sunxi_sid_cfg { diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c index 72e4faabce29..5ae9e002f195 100644 --- a/drivers/nvmem/vf610-ocotp.c +++ b/drivers/nvmem/vf610-ocotp.c @@ -206,7 +206,6 @@ static int vf610_ocotp_read(void *context, unsigned int offset, static struct nvmem_config ocotp_config = { .name = "ocotp", - .owner = THIS_MODULE, .stride = 4, .word_size = 4, .reg_read = vf610_ocotp_read, -- cgit v1.2.3-58-ga151 From 71c5dd5002b11d240c9b0e4adc972903183000aa Mon Sep 17 00:00:00 2001 From: Keiji Hayashibara Date: Tue, 24 Oct 2017 10:54:26 +0100 Subject: nvmem: uniphier: add UniPhier eFuse driver Add eFuse driver for Socionext UniPhier series SoC. Note that eFuse device is under soc-glue and this register implements as read only. Signed-off-by: Keiji Hayashibara Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/Kconfig | 11 +++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/uniphier-efuse.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 drivers/nvmem/uniphier-efuse.c (limited to 'drivers') diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index eb09916744bf..ff505af064ba 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -123,6 +123,17 @@ config NVMEM_SUNXI_SID This driver can also be built as a module. If so, the module will be called nvmem_sunxi_sid. +config UNIPHIER_EFUSE + tristate "UniPhier SoCs eFuse support" + depends on ARCH_UNIPHIER || COMPILE_TEST + depends on HAS_IOMEM + help + This is a simple driver to dump specified values of UniPhier SoC + from eFuse. + + This driver can also be built as a module. If so, the module + will be called nvmem-uniphier-efuse. + config NVMEM_VF610_OCOTP tristate "VF610 SoC OCOTP support" depends on SOC_VF610 || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 362f394da65d..64849e946d50 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -26,6 +26,8 @@ obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o nvmem_rockchip_efuse-y := rockchip-efuse.o obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o nvmem_sunxi_sid-y := sunxi_sid.o +obj-$(CONFIG_UNIPHIER_EFUSE) += nvmem-uniphier-efuse.o +nvmem-uniphier-efuse-y := uniphier-efuse.o obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o nvmem-vf610-ocotp-y := vf610-ocotp.o obj-$(CONFIG_MESON_EFUSE) += nvmem_meson_efuse.o diff --git a/drivers/nvmem/uniphier-efuse.c b/drivers/nvmem/uniphier-efuse.c new file mode 100644 index 000000000000..9d278b4e1dc7 --- /dev/null +++ b/drivers/nvmem/uniphier-efuse.c @@ -0,0 +1,97 @@ +/* + * UniPhier eFuse driver + * + * Copyright (C) 2017 Socionext Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +struct uniphier_efuse_priv { + void __iomem *base; +}; + +static int uniphier_reg_read(void *context, + unsigned int reg, void *_val, size_t bytes) +{ + struct uniphier_efuse_priv *priv = context; + u32 *val = _val; + int offs; + + for (offs = 0; offs < bytes; offs += sizeof(u32)) + *val++ = readl(priv->base + reg + offs); + + return 0; +} + +static int uniphier_efuse_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct nvmem_device *nvmem; + struct nvmem_config econfig = {}; + struct uniphier_efuse_priv *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->base = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + econfig.stride = 4; + econfig.word_size = 4; + econfig.read_only = true; + econfig.reg_read = uniphier_reg_read; + econfig.size = resource_size(res); + econfig.priv = priv; + econfig.dev = dev; + nvmem = nvmem_register(&econfig); + if (IS_ERR(nvmem)) + return PTR_ERR(nvmem); + + platform_set_drvdata(pdev, nvmem); + + return 0; +} + +static int uniphier_efuse_remove(struct platform_device *pdev) +{ + struct nvmem_device *nvmem = platform_get_drvdata(pdev); + + return nvmem_unregister(nvmem); +} + +static const struct of_device_id uniphier_efuse_of_match[] = { + { .compatible = "socionext,uniphier-efuse",}, + {/* sentinel */}, +}; +MODULE_DEVICE_TABLE(of, uniphier_efuse_of_match); + +static struct platform_driver uniphier_efuse_driver = { + .probe = uniphier_efuse_probe, + .remove = uniphier_efuse_remove, + .driver = { + .name = "uniphier-efuse", + .of_match_table = uniphier_efuse_of_match, + }, +}; +module_platform_driver(uniphier_efuse_driver); + +MODULE_AUTHOR("Keiji Hayashibara "); +MODULE_DESCRIPTION("UniPhier eFuse driver"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-58-ga151 From 9d6a8dab8d8b94975d7d78a7866053bd1c9444ca Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:27 +0100 Subject: nvmem: imx-ocotp: Restrict OTP write to IMX6 processors i.MX7S/D have a different scheme for addressing the OTP registers inside the OCOTP block. Currently it's possible to address the wrong OTP registers given the disparity between IMX6 and IMX7 OTP addressing. Since OTP programming is one-time destructive its important we restrict this interface ASAP. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Acked-by: Philipp Zabel Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e57e2a57aa3f..653cff9d9927 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -346,6 +346,8 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; priv->config = &imx_ocotp_nvmem_config; + if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx7d-ocotp")) + imx_ocotp_nvmem_config.read_only = true; nvmem = nvmem_register(&imx_ocotp_nvmem_config); if (IS_ERR(nvmem)) -- cgit v1.2.3-58-ga151 From e20d2b291ba2f5441fd4aacd746c21e60d48b559 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:28 +0100 Subject: nvmem: imx-ocotp: Pass parameters via a struct It will be useful in later patches to know the register access mode and bit-shift to apply to a given input offset. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Reviewed-by: Philipp Zabel Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 653cff9d9927..d94ed2d69a10 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -53,11 +53,15 @@ static DEFINE_MUTEX(ocotp_mutex); +struct ocotp_params { + unsigned int nregs; +}; + struct ocotp_priv { struct device *dev; struct clk *clk; void __iomem *base; - unsigned int nregs; + const struct ocotp_params *params; struct nvmem_config *config; }; @@ -121,8 +125,8 @@ static int imx_ocotp_read(void *context, unsigned int offset, index = offset >> 2; count = bytes >> 2; - if (count > (priv->nregs - index)) - count = priv->nregs - index; + if (count > (priv->params->nregs - index)) + count = priv->params->nregs - index; mutex_lock(&ocotp_mutex); @@ -307,12 +311,32 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .reg_write = imx_ocotp_write, }; +static const struct ocotp_params imx6q_params = { + .nregs = 128, +}; + +static const struct ocotp_params imx6sl_params = { + .nregs = 64, +}; + +static const struct ocotp_params imx6sx_params = { + .nregs = 128, +}; + +static const struct ocotp_params imx6ul_params = { + .nregs = 128, +}; + +static const struct ocotp_params imx7d_params = { + .nregs = 64, +}; + static const struct of_device_id imx_ocotp_dt_ids[] = { - { .compatible = "fsl,imx6q-ocotp", (void *)128 }, - { .compatible = "fsl,imx6sl-ocotp", (void *)64 }, - { .compatible = "fsl,imx6sx-ocotp", (void *)128 }, - { .compatible = "fsl,imx6ul-ocotp", (void *)128 }, - { .compatible = "fsl,imx7d-ocotp", (void *)64 }, + { .compatible = "fsl,imx6q-ocotp", .data = &imx6q_params }, + { .compatible = "fsl,imx6sl-ocotp", .data = &imx6sl_params }, + { .compatible = "fsl,imx6sx-ocotp", .data = &imx6sx_params }, + { .compatible = "fsl,imx6ul-ocotp", .data = &imx6ul_params }, + { .compatible = "fsl,imx7d-ocotp", .data = &imx7d_params }, { }, }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); @@ -341,8 +365,8 @@ static int imx_ocotp_probe(struct platform_device *pdev) return PTR_ERR(priv->clk); of_id = of_match_device(imx_ocotp_dt_ids, dev); - priv->nregs = (unsigned long)of_id->data; - imx_ocotp_nvmem_config.size = 4 * priv->nregs; + priv->params = of_device_get_match_data(&pdev->dev); + imx_ocotp_nvmem_config.size = 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; priv->config = &imx_ocotp_nvmem_config; -- cgit v1.2.3-58-ga151 From ffd9115f6548c51d347489e76bfb7d10e728f43d Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:29 +0100 Subject: nvmem: imx-ocotp: Add support for banked OTP addressing The i.MX7S/D takes the bank address in the CTRLn.ADDR field and the data value in one of the DATAx {0, 1, 2, 3} register fields. The current write routine is based on writing the CTRLn.ADDR field and writing a single DATA register only. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Reviewed-by: Philipp Zabel Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 68 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index d94ed2d69a10..bf95a0ecd0dc 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -40,7 +40,10 @@ #define IMX_OCOTP_ADDR_CTRL_SET 0x0004 #define IMX_OCOTP_ADDR_CTRL_CLR 0x0008 #define IMX_OCOTP_ADDR_TIMING 0x0010 -#define IMX_OCOTP_ADDR_DATA 0x0020 +#define IMX_OCOTP_ADDR_DATA0 0x0020 +#define IMX_OCOTP_ADDR_DATA1 0x0030 +#define IMX_OCOTP_ADDR_DATA2 0x0040 +#define IMX_OCOTP_ADDR_DATA3 0x0050 #define IMX_OCOTP_BM_CTRL_ADDR 0x0000007F #define IMX_OCOTP_BM_CTRL_BUSY 0x00000100 @@ -55,6 +58,7 @@ static DEFINE_MUTEX(ocotp_mutex); struct ocotp_params { unsigned int nregs; + unsigned int bank_address_words; }; struct ocotp_priv { @@ -176,6 +180,7 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, u32 timing = 0; u32 ctrl; u8 waddr; + u8 word = 0; /* allow only writing one complete OTP word at a time */ if ((bytes != priv->config->word_size) || @@ -228,8 +233,23 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, * description. Both the unlock code and address can be written in the * same operation. */ - /* OTP write/read address specifies one of 128 word address locations */ - waddr = offset / 4; + if (priv->params->bank_address_words != 0) { + /* + * In banked/i.MX7 mode the OTP register bank goes into waddr + * see i.MX 7Solo Applications Processor Reference Manual, Rev. + * 0.1 section 6.4.3.1 + */ + offset = offset / priv->config->word_size; + waddr = offset / priv->params->bank_address_words; + word = offset & (priv->params->bank_address_words - 1); + } else { + /* + * Non-banked i.MX6 mode. + * OTP write/read address specifies one of 128 word address + * locations + */ + waddr = offset / 4; + } ctrl = readl(priv->base + IMX_OCOTP_ADDR_CTRL); ctrl &= ~IMX_OCOTP_BM_CTRL_ADDR; @@ -255,8 +275,43 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, * shift right (with zero fill). This shifting is required to program * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be * modified. + * Note: on i.MX7 there are four data fields to write for banked write + * with the fuse blowing operation only taking place after data0 + * has been written. This is why data0 must always be the last + * register written. */ - writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA); + if (priv->params->bank_address_words != 0) { + /* Banked/i.MX7 mode */ + switch (word) { + case 0: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 1: + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 2: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 3: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + } + } else { + /* Non-banked i.MX6 mode */ + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); + } /* 47.4.1.4.5 * Once complete, the controller will clear BUSY. A write request to a @@ -313,22 +368,27 @@ static struct nvmem_config imx_ocotp_nvmem_config = { static const struct ocotp_params imx6q_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx6sl_params = { .nregs = 64, + .bank_address_words = 0, }; static const struct ocotp_params imx6sx_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx6ul_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx7d_params = { .nregs = 64, + .bank_address_words = 4, }; static const struct of_device_id imx_ocotp_dt_ids[] = { -- cgit v1.2.3-58-ga151 From b50cb68f16ce393db040f755dcb26b9a246180c4 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:30 +0100 Subject: nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function The i.MX7S/D has a different set of timing requirements, as a pre-cursor to adding the i.MX7 timing parameters, move the i.MX6 stuff to a dedicated function. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Reviewed-by: Philipp Zabel Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index bf95a0ecd0dc..8136ce8e77cd 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -168,6 +168,31 @@ read_end: return ret; } +static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) +{ + unsigned long clk_rate = 0; + unsigned long strobe_read, relax, strobe_prog; + u32 timing = 0; + + /* 47.3.1.3.1 + * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] + * fields with timing values to match the current frequency of the + * ipg_clk. OTP writes will work at maximum bus frequencies as long + * as the HW_OCOTP_TIMING parameters are set correctly. + */ + clk_rate = clk_get_rate(priv->clk); + + relax = clk_rate / (1000000000 / DEF_RELAX) - 1; + strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; + strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; + + timing = strobe_prog & 0x00000FFF; + timing |= (relax << 12) & 0x0000F000; + timing |= (strobe_read << 16) & 0x003F0000; + + writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); +} + static int imx_ocotp_write(void *context, unsigned int offset, void *val, size_t bytes) { @@ -175,9 +200,6 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, u32 *buf = val; int ret; - unsigned long clk_rate = 0; - unsigned long strobe_read, relax, strobe_prog; - u32 timing = 0; u32 ctrl; u8 waddr; u8 word = 0; @@ -196,23 +218,8 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, return ret; } - /* 47.3.1.3.1 - * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] - * fields with timing values to match the current frequency of the - * ipg_clk. OTP writes will work at maximum bus frequencies as long - * as the HW_OCOTP_TIMING parameters are set correctly. - */ - clk_rate = clk_get_rate(priv->clk); - - relax = clk_rate / (1000000000 / DEF_RELAX) - 1; - strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; - strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; - - timing = strobe_prog & 0x00000FFF; - timing |= (relax << 12) & 0x0000F000; - timing |= (strobe_read << 16) & 0x003F0000; - - writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); + /* Setup the write timing values */ + imx_ocotp_set_imx6_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. -- cgit v1.2.3-58-ga151 From 828ae7a47caf86570f19b78d0923b3ea89714168 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:31 +0100 Subject: nvmem: imx-ocotp: Add i.MX7D timing write clock setup support This patch adds logic to correctly setup the write timing parameters when blowing an OTP fuse for the i.MX7S/D. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 8136ce8e77cd..10fc4a70a6e5 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -50,17 +50,14 @@ #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 -#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_FSOURCE 1001 /* > 1000 ns */ +#define DEF_STROBE_PROG 10000 /* IPG clocks */ #define IMX_OCOTP_WR_UNLOCK 0x3E770000 #define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA static DEFINE_MUTEX(ocotp_mutex); -struct ocotp_params { - unsigned int nregs; - unsigned int bank_address_words; -}; - struct ocotp_priv { struct device *dev; struct clk *clk; @@ -69,6 +66,12 @@ struct ocotp_priv { struct nvmem_config *config; }; +struct ocotp_params { + unsigned int nregs; + unsigned int bank_address_words; + void (*set_timing)(struct ocotp_priv *priv); +}; + static int imx_ocotp_wait_for_busy(void __iomem *base, u32 flags) { int count; @@ -193,6 +196,27 @@ static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); } +static void imx_ocotp_set_imx7_timing(struct ocotp_priv *priv) +{ + unsigned long clk_rate = 0; + u64 fsource, strobe_prog; + u32 timing = 0; + + /* i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1 + * 6.4.3.3 + */ + clk_rate = clk_get_rate(priv->clk); + fsource = DIV_ROUND_UP_ULL((u64)clk_rate * DEF_FSOURCE, + NSEC_PER_SEC) + 1; + strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG, + NSEC_PER_SEC) + 1; + + timing = strobe_prog & 0x00000FFF; + timing |= (fsource << 12) & 0x000FF000; + + writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); +} + static int imx_ocotp_write(void *context, unsigned int offset, void *val, size_t bytes) { @@ -219,7 +243,7 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, } /* Setup the write timing values */ - imx_ocotp_set_imx6_timing(priv); + priv->params->set_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. @@ -376,26 +400,31 @@ static struct nvmem_config imx_ocotp_nvmem_config = { static const struct ocotp_params imx6q_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sl_params = { .nregs = 64, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sx_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6ul_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx7d_params = { .nregs = 64, .bank_address_words = 4, + .set_timing = imx_ocotp_set_imx7_timing, }; static const struct of_device_id imx_ocotp_dt_ids[] = { -- cgit v1.2.3-58-ga151 From a32bab320fe1e9d5c4fd70f1d7ad92be46a9fcd3 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:32 +0100 Subject: nvmem: imx-ocotp: Enable i.MX7D OTP write support After applying patches for both banked access and write timings we can re-enable the OTP write interface on i.MX7D processors. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 10fc4a70a6e5..d56d481eca57 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -466,8 +466,6 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; priv->config = &imx_ocotp_nvmem_config; - if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx7d-ocotp")) - imx_ocotp_nvmem_config.read_only = true; nvmem = nvmem_register(&imx_ocotp_nvmem_config); if (IS_ERR(nvmem)) -- cgit v1.2.3-58-ga151 From aef9a4de2afa25c02b1d112211ce29e6453ad210 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 24 Oct 2017 10:54:33 +0100 Subject: nvmem: imx-ocotp: Update module description This imx-ocotp driver encapsulates support for a subset of both i.MX6 and i.MX7 processors. Update the module description to reflect. Fixes: 711d45477931 ("nvmem: octop: Add i.MX7D support") Signed-off-by: Bryan O'Donoghue Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/imx-ocotp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index d56d481eca57..d7ba351a70c9 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -494,5 +494,5 @@ static struct platform_driver imx_ocotp_driver = { module_platform_driver(imx_ocotp_driver); MODULE_AUTHOR("Philipp Zabel "); -MODULE_DESCRIPTION("i.MX6 OCOTP fuse box driver"); +MODULE_DESCRIPTION("i.MX6/i.MX7 OCOTP fuse box driver"); MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-58-ga151 From b7fe57b802c4f12da20920229acb9fff92300ad4 Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Tue, 24 Oct 2017 10:54:34 +0100 Subject: nvmem: sunxi-sid: add support for A64/H5's SID controller Allwinner A64/H5 SoCs come with a SID controller like the one in H3, but without the silicon bug that makes the initial value at 0x200 wrong, so the value at 0x200 can be directly read. Add support for this kind of SID controller. Signed-off-by: Icenowy Zheng Acked-by: Rob Herring Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt | 1 + drivers/nvmem/sunxi_sid.c | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt b/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt index ef06d061913c..6ea0836939ee 100644 --- a/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt +++ b/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt @@ -5,6 +5,7 @@ Required properties: "allwinner,sun4i-a10-sid" "allwinner,sun7i-a20-sid" "allwinner,sun8i-h3-sid" + "allwinner,sun50i-a64-sid" - reg: Should contain registers location and length diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 1c3b5cf89212..99bd54d85fcb 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -198,10 +198,16 @@ static const struct sunxi_sid_cfg sun8i_h3_cfg = { .need_register_readout = true, }; +static const struct sunxi_sid_cfg sun50i_a64_cfg = { + .value_offset = 0x200, + .size = 0x100, +}; + static const struct of_device_id sunxi_sid_of_match[] = { { .compatible = "allwinner,sun4i-a10-sid", .data = &sun4i_a10_cfg }, { .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg }, { .compatible = "allwinner,sun8i-h3-sid", .data = &sun8i_h3_cfg }, + { .compatible = "allwinner,sun50i-a64-sid", .data = &sun50i_a64_cfg }, {/* sentinel */}, }; MODULE_DEVICE_TABLE(of, sunxi_sid_of_match); -- cgit v1.2.3-58-ga151 From f53459c00871a7c3db5b69b49d840ca9d497a695 Mon Sep 17 00:00:00 2001 From: Alexey Khoroshilov Date: Sun, 22 Oct 2017 01:03:44 +0300 Subject: w1: keep balance of mutex locks and refcnts w1_therm_eeprom() and w1_DS18B20_precision() decrement THERM_REFCNT on error paths, while they did not increment it yet. read_therm() unlocks bus mutex on some error paths, while it is not acquired. The patch makes sure all the functions keep the balance in usage of the mutex and the THERM_REFCNT. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_therm.c | 59 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c index 259525c3382a..3c350dfbcd0b 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c @@ -268,17 +268,18 @@ static inline int w1_therm_eeprom(struct device *device) int ret, max_trying = 10; u8 *family_data = sl->family_data; - ret = mutex_lock_interruptible(&dev->bus_mutex); - if (ret != 0) - goto post_unlock; - if (!sl->family_data) { ret = -ENODEV; - goto pre_unlock; + goto error; } /* prevent the slave from going away in sleep */ atomic_inc(THERM_REFCNT(family_data)); + + ret = mutex_lock_interruptible(&dev->bus_mutex); + if (ret != 0) + goto dec_refcnt; + memset(rom, 0, sizeof(rom)); while (max_trying--) { @@ -306,17 +307,17 @@ static inline int w1_therm_eeprom(struct device *device) sleep_rem = msleep_interruptible(tm); if (sleep_rem != 0) { ret = -EINTR; - goto post_unlock; + goto dec_refcnt; } ret = mutex_lock_interruptible(&dev->bus_mutex); if (ret != 0) - goto post_unlock; + goto dec_refcnt; } else if (!w1_strong_pullup) { sleep_rem = msleep_interruptible(tm); if (sleep_rem != 0) { ret = -EINTR; - goto pre_unlock; + goto mt_unlock; } } @@ -324,11 +325,11 @@ static inline int w1_therm_eeprom(struct device *device) } } -pre_unlock: +mt_unlock: mutex_unlock(&dev->bus_mutex); - -post_unlock: +dec_refcnt: atomic_dec(THERM_REFCNT(family_data)); +error: return ret; } @@ -350,20 +351,22 @@ static inline int w1_DS18B20_precision(struct device *device, int val) if (val > 12 || val < 9) { pr_warn("Unsupported precision\n"); - return -1; + ret = -EINVAL; + goto error; } - ret = mutex_lock_interruptible(&dev->bus_mutex); - if (ret != 0) - goto post_unlock; - if (!sl->family_data) { ret = -ENODEV; - goto pre_unlock; + goto error; } /* prevent the slave from going away in sleep */ atomic_inc(THERM_REFCNT(family_data)); + + ret = mutex_lock_interruptible(&dev->bus_mutex); + if (ret != 0) + goto dec_refcnt; + memset(rom, 0, sizeof(rom)); /* translate precision to bitmask (see datasheet page 9) */ @@ -411,11 +414,10 @@ static inline int w1_DS18B20_precision(struct device *device, int val) } } -pre_unlock: mutex_unlock(&dev->bus_mutex); - -post_unlock: +dec_refcnt: atomic_dec(THERM_REFCNT(family_data)); +error: return ret; } @@ -490,17 +492,18 @@ static ssize_t read_therm(struct device *device, int ret, max_trying = 10; u8 *family_data = sl->family_data; - ret = mutex_lock_interruptible(&dev->bus_mutex); - if (ret != 0) - goto error; - if (!family_data) { ret = -ENODEV; - goto mt_unlock; + goto error; } /* prevent the slave from going away in sleep */ atomic_inc(THERM_REFCNT(family_data)); + + ret = mutex_lock_interruptible(&dev->bus_mutex); + if (ret != 0) + goto dec_refcnt; + memset(info->rom, 0, sizeof(info->rom)); while (max_trying--) { @@ -542,7 +545,7 @@ static ssize_t read_therm(struct device *device, sleep_rem = msleep_interruptible(tm); if (sleep_rem != 0) { ret = -EINTR; - goto dec_refcnt; + goto mt_unlock; } } @@ -567,10 +570,10 @@ static ssize_t read_therm(struct device *device, break; } -dec_refcnt: - atomic_dec(THERM_REFCNT(family_data)); mt_unlock: mutex_unlock(&dev->bus_mutex); +dec_refcnt: + atomic_dec(THERM_REFCNT(family_data)); error: return ret; } -- cgit v1.2.3-58-ga151 From f13d1a8a801dae552ef495c84a223280586a9f67 Mon Sep 17 00:00:00 2001 From: Martyn Welch Date: Tue, 24 Oct 2017 08:27:40 +0200 Subject: VME: Return -EBUSY when DMA list in use The VME subsystem currently returns -EBUSY when trying to free a DMA resource that is busy, but returns -EINVAL when trying to free a DMA list that is in use. Switch to returning -EBUSY when trying to free a DMA list that is in use for consistency and correctness. Signed-off-by: Martyn Welch Signed-off-by: Greg Kroah-Hartman --- drivers/vme/vme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c index d0ce50d56019..81246221a13b 100644 --- a/drivers/vme/vme.c +++ b/drivers/vme/vme.c @@ -1194,7 +1194,7 @@ int vme_dma_list_free(struct vme_dma_list *list) if (!mutex_trylock(&list->mtx)) { printk(KERN_ERR "Link List in use\n"); - return -EINVAL; + return -EBUSY; } /* -- cgit v1.2.3-58-ga151