Commit 039cd25f authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'for-linus-5.1' of git://github.com/cminyard/linux-ipmi

Pull IPMI updates from Corey Minyard:
 "A couple of bug fixes and a bunch of code cleanup:

   - Fix a use after free error in a certain error situation.

   - Fix some flag handling issues in the SSIF (I2C) IPMI driver.

   - A bunch of cleanups, spacing issues, converting pr_xxx to dev_xxx,
     use standard UUID handling, and some other minor stuff.

   - The IPMI code was creating a platform device if none was supplied.
     Instead of doing that, have every source that creates an IPMI
     device supply a device struct. This fixes several issues,including
     a crash in one situation, and cleans things up a bit"

* tag 'for-linus-5.1' of git://github.com/cminyard/linux-ipmi:
  ipmi_si: Potential array underflow in hotmod_handler()
  ipmi_si: Remove hacks for adding a dummy platform devices
  ipmi_si: Consolidate scanning the platform bus
  ipmi_si: Remove hotmod devices on removal and exit
  ipmi_si: Remove hardcode IPMI devices by scanning the platform bus
  ipmi_si: Switch hotmod to use a platform device
  ipmi: Consolidate the adding of platform devices
  ipmi_si: Rename addr_type to addr_space to match what it does
  ipmi_si: Convert some types into unsigned
  ipmi_si: Fix crash when using hard-coded device
  ipmi: Use dedicated API for copying a UUID
  ipmi: Use defined constant for UUID representation
  ipmi:ssif: Change some pr_xxx to dev_xxx calls
  ipmi: kcs_bmc: handle devm_kasprintf() failure case
  ipmi: Fix return value when a message is truncated
  ipmi: clean an indentation issue, remove extraneous space
  ipmi: Make the smi watcher be disabled immediately when not needed
  ipmi: Fix how the lower layers are told to watch for messages
  ipmi: Fix SSIF flag requests
  ipmi_si: fix use-after-free of resource->name
parents e13284da 03890359
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ menuconfig IPMI_HANDLER
	 If unsure, say N.

config IPMI_DMI_DECODE
       select IPMI_PLAT_DATA
       bool

config IPMI_PLAT_DATA
       bool

if IPMI_HANDLER
@@ -56,6 +60,7 @@ config IPMI_DEVICE_INTERFACE

config IPMI_SI
       tristate 'IPMI System Interface handler'
       select IPMI_PLAT_DATA
       help
         Provides a driver for System Interfaces (KCS, SMIC, BT).
	 Currently, only KCS and SMIC are supported.  If
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o
obj-$(CONFIG_IPMI_SI) += ipmi_si.o
obj-$(CONFIG_IPMI_DMI_DECODE) += ipmi_dmi.o
obj-$(CONFIG_IPMI_PLAT_DATA) += ipmi_plat_data.o
obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
+3 −3
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ static int handle_recv(struct ipmi_file_private *priv,
	struct list_head *entry;
	struct ipmi_recv_msg  *msg;
	unsigned long    flags;
	int rv = 0;
	int rv = 0, rv2 = 0;

	/* We claim a mutex because we don't want two
	   users getting something from the queue at a time.
@@ -250,7 +250,7 @@ static int handle_recv(struct ipmi_file_private *priv,

	if (msg->msg.data_len > 0) {
		if (rsp->msg.data_len < msg->msg.data_len) {
			rv = -EMSGSIZE;
			rv2 = -EMSGSIZE;
			if (trunc)
				msg->msg.data_len = rsp->msg.data_len;
			else
@@ -274,7 +274,7 @@ static int handle_recv(struct ipmi_file_private *priv,

	mutex_unlock(&priv->recv_mutex);
	ipmi_free_recv_msg(msg);
	return 0;
	return rv2;

recv_putback_on_err:
	/* If we got an error, put the message back onto
+33 −106
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <linux/property.h>
#include "ipmi_si_sm.h"
#include "ipmi_dmi.h"
#include "ipmi_plat_data.h"

#define IPMI_DMI_TYPE_KCS	0x01
#define IPMI_DMI_TYPE_SMIC	0x02
@@ -22,7 +23,7 @@

struct ipmi_dmi_info {
	enum si_type si_type;
	u32 flags;
	unsigned int space; /* addr space for si, intf# for ssif */
	unsigned long addr;
	u8 slave_addr;
	struct ipmi_dmi_info *next;
@@ -33,133 +34,60 @@ static struct ipmi_dmi_info *ipmi_dmi_infos;
static int ipmi_dmi_nr __initdata;

static void __init dmi_add_platform_ipmi(unsigned long base_addr,
					 u32 flags,
					 unsigned int space,
					 u8 slave_addr,
					 int irq,
					 int offset,
					 int type)
{
	struct platform_device *pdev;
	struct resource r[4];
	unsigned int num_r = 1, size;
	struct property_entry p[5];
	unsigned int pidx = 0;
	char *name;
	int rv;
	enum si_type si_type;
	const char *name;
	struct ipmi_dmi_info *info;
	struct ipmi_plat_data p;

	memset(p, 0, sizeof(p));
	memset(&p, 0, sizeof(p));

	name = "dmi-ipmi-si";
	switch (type) {
	case IPMI_DMI_TYPE_SSIF:
		name = "dmi-ipmi-ssif";
		offset = 1;
		size = 1;
		si_type = SI_TYPE_INVALID;
		p.type = SI_TYPE_INVALID;
		break;
	case IPMI_DMI_TYPE_BT:
		size = 3;
		si_type = SI_BT;
		p.type = SI_BT;
		break;
	case IPMI_DMI_TYPE_KCS:
		size = 2;
		si_type = SI_KCS;
		p.type = SI_KCS;
		break;
	case IPMI_DMI_TYPE_SMIC:
		size = 2;
		si_type = SI_SMIC;
		p.type = SI_SMIC;
		break;
	default:
		pr_err("Invalid IPMI type: %d\n", type);
		return;
	}

	if (si_type != SI_TYPE_INVALID)
		p[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", si_type);

	p[pidx++] = PROPERTY_ENTRY_U8("slave-addr", slave_addr);
	p[pidx++] = PROPERTY_ENTRY_U8("addr-source", SI_SMBIOS);
	memset(&p, 0, sizeof(p));
	p.addr = base_addr;
	p.space = space;
	p.regspacing = offset;
	p.irq = irq;
	p.slave_addr = slave_addr;
	p.addr_source = SI_SMBIOS;

	info = kmalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		pr_warn("Could not allocate dmi info\n");
	} else {
		info->si_type = si_type;
		info->flags = flags;
		info->si_type = p.type;
		info->space = space;
		info->addr = base_addr;
		info->slave_addr = slave_addr;
		info->next = ipmi_dmi_infos;
		ipmi_dmi_infos = info;
	}

	pdev = platform_device_alloc(name, ipmi_dmi_nr);
	if (!pdev) {
		pr_err("Error allocation IPMI platform device\n");
		return;
	}

	if (type == IPMI_DMI_TYPE_SSIF) {
		p[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", base_addr);
		goto add_properties;
	}

	memset(r, 0, sizeof(r));

	r[0].start = base_addr;
	r[0].end = r[0].start + offset - 1;
	r[0].name = "IPMI Address 1";
	r[0].flags = flags;

	if (size > 1) {
		r[1].start = r[0].start + offset;
		r[1].end = r[1].start + offset - 1;
		r[1].name = "IPMI Address 2";
		r[1].flags = flags;
		num_r++;
	}

	if (size > 2) {
		r[2].start = r[1].start + offset;
		r[2].end = r[2].start + offset - 1;
		r[2].name = "IPMI Address 3";
		r[2].flags = flags;
		num_r++;
	}

	if (irq) {
		r[num_r].start = irq;
		r[num_r].end = irq;
		r[num_r].name = "IPMI IRQ";
		r[num_r].flags = IORESOURCE_IRQ;
		num_r++;
	}

	rv = platform_device_add_resources(pdev, r, num_r);
	if (rv) {
		dev_err(&pdev->dev, "Unable to add resources: %d\n", rv);
		goto err;
	}

add_properties:
	rv = platform_device_add_properties(pdev, p);
	if (rv) {
		dev_err(&pdev->dev, "Unable to add properties: %d\n", rv);
		goto err;
	}

	rv = platform_device_add(pdev);
	if (rv) {
		dev_err(&pdev->dev, "Unable to add device: %d\n", rv);
		goto err;
	}

	if (ipmi_platform_add(name, ipmi_dmi_nr, &p))
		ipmi_dmi_nr++;
	return;

err:
	platform_device_put(pdev);
}

/*
@@ -169,14 +97,14 @@ err:
 * This function allows an ACPI-specified IPMI device to look up the
 * slave address from the DMI table.
 */
int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags,
int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space,
			    unsigned long base_addr)
{
	struct ipmi_dmi_info *info = ipmi_dmi_infos;

	while (info) {
		if (info->si_type == si_type &&
		    info->flags == flags &&
		    info->space == space &&
		    info->addr == base_addr)
			return info->slave_addr;
		info = info->next;
@@ -198,11 +126,11 @@ EXPORT_SYMBOL(ipmi_dmi_get_slave_addr);
static void __init dmi_decode_ipmi(const struct dmi_header *dm)
{
	const u8 *data = (const u8 *) dm;
	u32             flags = IORESOURCE_IO;
	int space = IPMI_IO_ADDR_SPACE;
	unsigned long base_addr;
	u8 len = dm->length;
	u8 slave_addr;
	int             irq = 0, offset;
	int irq = 0, offset = 0;
	int type;

	if (len < DMI_IPMI_MIN_LENGTH)
@@ -218,8 +146,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
	}
	if (len >= DMI_IPMI_VER2_LENGTH) {
		if (type == IPMI_DMI_TYPE_SSIF) {
			offset = 0;
			flags = 0;
			space = 0; /* Match I2C interface 0. */
			base_addr = data[DMI_IPMI_ADDR] >> 1;
			if (base_addr == 0) {
				/*
@@ -236,7 +163,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
				base_addr &= DMI_IPMI_IO_MASK;
			} else {
				/* Memory */
				flags = IORESOURCE_MEM;
				space = IPMI_MEM_ADDR_SPACE;
			}

			/*
@@ -280,7 +207,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
		offset = 1;
	}

	dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq,
	dmi_add_platform_ipmi(base_addr, space, slave_addr, irq,
			      offset, type);
}

+1 −1
Original line number Diff line number Diff line
@@ -4,6 +4,6 @@
 */

#ifdef CONFIG_IPMI_DMI_DECODE
int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags,
int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space,
			    unsigned long base_addr);
#endif
Loading