device: correct code style

Revise the following aspects to follow coreboot's coding style:
 - Drop braces for single-statement condition and loop bodies.
 - Use `__func__` to print the current function's name.
 - Reflow pointer dereferences to fit in a single line.
 - Adjust the `*` position in pointer variable declarations.
 - Drop unnecessary `else` statements.

BUG = N/A
TEST = Build Compulab Intense-PC with secure oprom enabled

Change-Id: I780251d946d5bea97658476d61d25555ec768dfc
Signed-off-by: Frans Hendriks <fhendriks@eltan.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/49963
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Frans Hendriks 2021-02-01 11:44:37 +01:00 committed by Patrick Georgi
parent 3d6d1075b2
commit a9caa50e8a
5 changed files with 41 additions and 46 deletions

View file

@ -174,9 +174,9 @@ static int wait_for_valid(u8 *base)
reg32 |= HDA_ICII_BUSY | HDA_ICII_VALID;
write32(base + HDA_ICII_REG, reg32);
while (timeout--) {
while (timeout--)
udelay(1);
}
timeout = 50;
while (timeout--) {
reg32 = read32(base + HDA_ICII_REG);

View file

@ -166,8 +166,8 @@ static void read_resources(struct bus *bus)
if (!curdev->ops || !curdev->ops->read_resources) {
if (curdev->path.type != DEVICE_PATH_APIC)
printk(BIOS_ERR, "%s missing read_resources\n",
dev_path(curdev));
printk(BIOS_ERR, "%s missing %s\n",
dev_path(curdev), __func__);
continue;
}
post_log_path(curdev);
@ -178,8 +178,8 @@ static void read_resources(struct bus *bus)
read_resources(link);
}
post_log_clear();
printk(BIOS_SPEW, "%s read_resources bus %d link: %d done\n",
dev_path(bus->dev), bus->secondary, bus->link_num);
printk(BIOS_SPEW, "%s %s bus %d link: %d done\n",
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
}
struct device *vga_pri = NULL;
@ -210,11 +210,10 @@ static void set_vga_bridge_bits(void)
"A bridge on the path doesn't support 16-bit VGA decoding!");
}
if (dev->on_mainboard) {
if (dev->on_mainboard)
vga_onboard = dev;
} else {
else
vga = dev;
}
/* It isn't safe to enable all VGA cards. */
dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
@ -269,8 +268,8 @@ void assign_resources(struct bus *bus)
{
struct device *curdev;
printk(BIOS_SPEW, "%s assign_resources, bus %d link: %d\n",
dev_path(bus->dev), bus->secondary, bus->link_num);
printk(BIOS_SPEW, "%s %s, bus %d link: %d\n",
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
if (!curdev->enabled || !curdev->resource_list)
@ -285,8 +284,8 @@ void assign_resources(struct bus *bus)
curdev->ops->set_resources(curdev);
}
post_log_clear();
printk(BIOS_SPEW, "%s assign_resources, bus %d link: %d\n",
dev_path(bus->dev), bus->secondary, bus->link_num);
printk(BIOS_SPEW, "%s %s, bus %d link: %d\n",
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
}
/**

View file

@ -9,7 +9,7 @@
#include <device/resource.h>
/** Linked list of ALL devices */
DEVTREE_CONST struct device * DEVTREE_CONST all_devices = &dev_root;
DEVTREE_CONST struct device *DEVTREE_CONST all_devices = &dev_root;
/**
* Given a PCI bus and a devfn number, find the device structure.

View file

@ -370,7 +370,8 @@ struct resource *new_resource(struct device *dev, unsigned int index)
resource->next = NULL;
tail = dev->resource_list;
if (tail) {
while (tail->next) tail = tail->next;
while (tail->next)
tail = tail->next;
tail->next = resource;
} else {
dev->resource_list = resource;
@ -555,7 +556,7 @@ void search_bus_resources(struct bus *bus, unsigned long type_mask,
/* If it is a subtractive resource recurse. */
if (res->flags & IORESOURCE_SUBTRACTIVE) {
struct bus * subbus;
struct bus *subbus;
for (subbus = curdev->link_list; subbus;
subbus = subbus->next)
if (subbus->link_num
@ -604,11 +605,10 @@ void dev_set_enabled(struct device *dev, int enable)
return;
dev->enabled = enable;
if (dev->ops && dev->ops->enable) {
if (dev->ops && dev->ops->enable)
dev->ops->enable(dev);
} else if (dev->chip_ops && dev->chip_ops->enable_dev) {
else if (dev->chip_ops && dev->chip_ops->enable_dev)
dev->chip_ops->enable_dev(dev);
}
}
void disable_children(struct bus *bus)
@ -814,7 +814,7 @@ void show_one_resource(int debug_level, struct device *dev,
buf, resource_type(resource), comment);
}
void show_all_devs_resources(int debug_level, const char* msg)
void show_all_devs_resources(int debug_level, const char *msg)
{
struct device *dev;

View file

@ -48,19 +48,17 @@ int i2c_dev_readb(struct device *const dev)
.len = sizeof(val),
};
const int ret = busdev->ops->ops_i2c_bus->
transfer(busdev, &msg, 1);
const int ret = busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1);
if (ret)
return ret;
else
return val;
} else if (busdev->ops->ops_smbus_bus->recv_byte) {
return busdev->ops->ops_smbus_bus->recv_byte(dev);
} else {
printk(BIOS_ERR, "%s Missing ops_smbus_bus->recv_byte",
dev_path(busdev));
return -1;
}
printk(BIOS_ERR, "%s Missing ops_smbus_bus->recv_byte", dev_path(busdev));
return -1;
}
int i2c_dev_writeb(struct device *const dev, uint8_t val)
@ -79,11 +77,11 @@ int i2c_dev_writeb(struct device *const dev, uint8_t val)
return busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1);
} else if (busdev->ops->ops_smbus_bus->send_byte) {
return busdev->ops->ops_smbus_bus->send_byte(dev, val);
} else {
printk(BIOS_ERR, "%s Missing ops_smbus_bus->send_byte",
dev_path(busdev));
return -1;
}
printk(BIOS_ERR, "%s Missing ops_smbus_bus->send_byte",
dev_path(busdev));
return -1;
}
int i2c_dev_readb_at(struct device *const dev, uint8_t off)
@ -109,23 +107,21 @@ int i2c_dev_readb_at(struct device *const dev, uint8_t off)
},
};
const int ret = busdev->ops->ops_i2c_bus->
transfer(busdev, msg, ARRAY_SIZE(msg));
const int ret = busdev->ops->ops_i2c_bus->transfer(busdev, msg,
ARRAY_SIZE(msg));
if (ret)
return ret;
else
return val;
} else if (busdev->ops->ops_smbus_bus->read_byte) {
return busdev->ops->ops_smbus_bus->read_byte(dev, off);
} else {
printk(BIOS_ERR, "%s Missing ops_smbus_bus->read_byte",
dev_path(busdev));
return -1;
}
printk(BIOS_ERR, "%s Missing ops_smbus_bus->read_byte", dev_path(busdev));
return -1;
}
int i2c_dev_writeb_at(struct device *const dev,
const uint8_t off, const uint8_t val)
int i2c_dev_writeb_at(struct device *const dev, const uint8_t off, const uint8_t val)
{
struct device *const busdev = i2c_busdev(dev);
if (!busdev)
@ -142,15 +138,15 @@ int i2c_dev_writeb_at(struct device *const dev,
return busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1);
} else if (busdev->ops->ops_smbus_bus->write_byte) {
return busdev->ops->ops_smbus_bus->write_byte(dev, off, val);
} else {
printk(BIOS_ERR, "%s Missing ops_smbus_bus->write_byte",
dev_path(busdev));
return -1;
}
printk(BIOS_ERR, "%s Missing ops_smbus_bus->write_byte",
dev_path(busdev));
return -1;
}
int i2c_dev_read_at16(struct device *const dev,
uint8_t *const buf, const size_t len, uint16_t off)
int i2c_dev_read_at16(struct device *const dev, uint8_t *const buf, const size_t len,
uint16_t off)
{
struct device *const busdev = i2c_busdev(dev);
if (!busdev)
@ -173,8 +169,8 @@ int i2c_dev_read_at16(struct device *const dev,
};
write_be16(&off, off);
const int ret = busdev->ops->ops_i2c_bus->transfer(
busdev, msg, ARRAY_SIZE(msg));
const int ret = busdev->ops->ops_i2c_bus->transfer(busdev, msg,
ARRAY_SIZE(msg));
if (ret)
return ret;
else