soundwire: some cleanup patches
Subsystems (3)
Bard Liao
maintainercover soundwire: some cleanup patches
To make soundwire driver more decent and less Cppcheck complaint.
Pierre-Louis Bossart (11):
soundwire: bus: use correct driver name in error messages
soundwire: bus: test read status
soundwire: bus: use consistent tests for return values
soundwire: bus: demote clock stop prepare log to dev_dbg()
soundwire: bus: uniquify dev_err() for SCP_INT access
soundwire: bus: remove useless initialization
soundwire: generic_bandwidth_allocation: remove useless init
soundwire: intel: remove useless readl
soundwire: qcom: check of_property_read status
soundwire: stream: remove useless initialization
soundwire: stream: remove useless bus initializations
drivers/soundwire/bus.c | 54 +++++++++++-------- drivers/soundwire/bus_type.c | 15 ++++-- .../soundwire/generic_bandwidth_allocation.c | 4 +- drivers/soundwire/intel.c | 2 - drivers/soundwire/qcom.c | 3 ++ drivers/soundwire/stream.c | 8 +-- 6 files changed, 52 insertions(+), 34 deletions(-)
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 1/11 soundwire: bus: use correct driver name in error messages
From: Pierre-Louis Bossart <[email protected]>
None of the existing codec drivers set the sdw_driver.name, but instead set sdw_driver.driver.name.
This leads to error messages such as
[ 23.935355] rt700 sdw:2:25d:700:0: Probe of (null) failed: -19
We could remove this sdw_driver.name if it doesn't have any purpose. This patch only suggests using the proper indirection.
--- drivers/soundwire/bus_type.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/soundwire/bus_type.c +12 -3
@@ -82,6 +82,7 @@ static int sdw_drv_probe(struct device *dev)struct sdw_slave *slave =dev_to_sdw_dev (dev);struct sdw_driver *drv =drv_to_sdw_driver (dev->driver);const struct sdw_device_id *id; +const char *name;int ret;/*
@@ -108,7 +109,10 @@ static int sdw_drv_probe(struct device *dev) ret = drv->probe (slave, id);if (ret) { -dev_err (dev,"Probe of %s failed: %d\n" , drv->name, ret); + name = drv->name; +if (!name) + name = drv->driver.name; +dev_err (dev,"Probe of %s failed: %d\n" , name, ret);dev_pm_domain_detach (dev, false);return ret; }
@@ -174,11 +178,16 @@ static void sdw_drv_shutdown(struct device *dev)*/ int __sdw_register_driver (struct sdw_driver *drv,struct module *owner) { +const char *name; + drv->driver.bus = &sdw_bus_type;if (!drv->probe) { -pr_err ("driver %s didn't provide SDW probe routine\n" , - drv->name); + name = drv->name; +if (!name) + name = drv->driver.name; + +pr_err ("driver %s didn't provide SDW probe routine\n" , name);return -EINVAL ; }
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 2/11 soundwire: bus: test read status
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
In the existing code we may read a negative error value but still mask it and write it back.
Make sure all reads are tested and errors not propagated further.
--- drivers/soundwire/bus.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/soundwire/bus.c +12 -4
@@ -875,8 +875,12 @@ static int sdw_slave_clk_stop_prepare(struct sdw_slave *slave,if (wake_en) val |=SDW_SCP_SYSTEMCTRL_WAKE_UP_EN ; }else { - val =sdw_read_no_pm (slave,SDW_SCP_SYSTEMCTRL ); - + ret =sdw_read_no_pm (slave,SDW_SCP_SYSTEMCTRL ); +if (ret <0 ) { +dev_err (&slave->dev,"SDW_SCP_SYSTEMCTRL read failed:%d\n" , ret); +return ret; + } + val = ret; val &= ~(SDW_SCP_SYSTEMCTRL_CLK_STP_PREP ); }
@@ -895,8 +899,12 @@ static int sdw_bus_wait_for_clk_prep_deprep(struct sdw_bus *bus, u16 dev_num)int val; do { - val = sdw_bread_no_pm(bus, dev_num, SDW_SCP_STAT) & - SDW_SCP_STAT_CLK_STP_NF; + val = sdw_bread_no_pm(bus, dev_num, SDW_SCP_STAT); + if (val < 0) { + dev_err(bus->dev, "SDW_SCP_STAT bread failed:%d\n", val); + return val; + } + val &= SDW_SCP_STAT_CLK_STP_NF; if (!val) { dev_info(bus->dev, "clock stop prep/de-prep done slave:%d", dev_num);
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 3/11 soundwire: bus: use consistent tests for return values
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
We use different styles to check the return values of IO related routines. The majority of the cases use 'if (ret < 0)', align the remaining cases for consistency.
--- drivers/soundwire/bus.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/soundwire/bus.c +13 -13
@@ -44,13 +44,13 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, } ret =sdw_get_id (bus); -if (ret) { +if (ret <0 ) {dev_err (parent,"Failed to get bus id\n" );return ret; } ret =sdw_master_device_add (bus, parent, fwnode); -if (ret) { +if (ret <0 ) {dev_err (parent,"Failed to add master device at link %d\n" , bus->link_id);return ret;
@@ -121,7 +121,7 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,else ret = -ENOTSUPP ;/* No ACPI/DT so error out */ -if (ret) { +if (ret <0 ) {dev_err (bus->dev,"Finding slaves failed:%d\n" , ret);return ret; }
@@ -422,7 +422,7 @@ sdw_bread_no_pm(struct sdw_bus *bus, u16 dev_num, u32 addr) ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num,SDW_MSG_FLAG_READ , &buf); -if (ret) +if (ret <0 )return ret; ret =sdw_transfer (bus, &msg);
@@ -440,7 +440,7 @@ sdw_bwrite_no_pm(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value) ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num,SDW_MSG_FLAG_WRITE , &value); -if (ret) +if (ret <0 )return ret;return sdw_transfer (bus, &msg);
@@ -454,7 +454,7 @@ int sdw_bread_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr) ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num,SDW_MSG_FLAG_READ , &buf); -if (ret) +if (ret <0 )return ret; ret =sdw_transfer_unlocked (bus, &msg);
@@ -472,7 +472,7 @@ int sdw_bwrite_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 val ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num,SDW_MSG_FLAG_WRITE , &value); -if (ret) +if (ret <0 )return ret;return sdw_transfer_unlocked (bus, &msg);
@@ -749,7 +749,7 @@ static int sdw_program_device_num(struct sdw_bus *bus)* dev_num */ ret =sdw_assign_device_num (slave); -if (ret) { +if (ret <0 ) {dev_err (bus->dev,"Assign dev_num failed:%d\n" , ret);
@@ -886,7 +886,7 @@ static int sdw_slave_clk_stop_prepare(struct sdw_slave *slave, ret =sdw_write_no_pm (slave,SDW_SCP_SYSTEMCTRL , val); -if (ret !=0 ) +if (ret <0 )dev_err (&slave->dev,"Clock Stop prepare failed for slave: %d" , ret);
@@ -1709,7 +1709,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus,if (status[0 ] ==SDW_SLAVE_ATTACHED ) {dev_dbg (bus->dev,"Slave attached, programming device number\n" ); ret =sdw_program_device_num (bus); -if (ret) +if (ret <0 )dev_err (bus->dev,"Slave attach failed: %d\n" , ret);/* * programming a device number will have side effects,
@@ -1743,7 +1743,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus,case SDW_SLAVE_ALERT : ret =sdw_handle_slave_alerts (slave); -if (ret) +if (ret <0 )dev_err (&slave->dev,"Slave %d alert handling failed: %d\n" , i, ret);
@@ -1762,7 +1762,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus, attached_initializing = true; ret =sdw_initialize_slave (slave); -if (ret) +if (ret <0 )dev_err (&slave->dev,"Slave %d initialization failed: %d\n" , i, ret);
@@ -1776,7 +1776,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus, } ret =sdw_update_slave_status (slave, status[i]); -if (ret) +if (ret <0 )dev_err (&slave->dev,"Update Slave status failed:%d\n" , ret);if (attached_initializing) {
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 4/11 soundwire: bus: demote clock stop prepare log to dev_dbg()
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
There is no real reason to provide this information except for debug sessions, hence dev_dbg() is a better fit.
--- drivers/soundwire/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soundwire/bus.c +2 -2
@@ -906,8 +906,8 @@ static int sdw_bus_wait_for_clk_prep_deprep(struct sdw_bus *bus, u16 dev_num) } val &=SDW_SCP_STAT_CLK_STP_NF ;if (!val) { -dev_info (bus->dev,"clock stop prep/de-prep done slave:%d" , - dev_num); +dev_dbg (bus->dev,"clock stop prep/de-prep done slave:%d" , + dev_num);return 0 ; }
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 5/11 soundwire: bus: uniquify dev_err() for SCP_INT access
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
We have multiple cases where we read/write SCP_INT registers, but the same error message in all cases. Add a distinct error message for each case to help debug.
--- drivers/soundwire/bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soundwire/bus.c +3 -3
@@ -1597,7 +1597,7 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) ret =sdw_read_no_pm (slave,SDW_SCP_INT1 );if (ret <0 ) {dev_err (&slave->dev, -"SDW_SCP_INT1 read failed:%d\n" , ret); +"SDW_SCP_INT1 recheck read failed:%d\n" , ret); goto io_err; } _buf = ret;
@@ -1605,7 +1605,7 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) ret =sdw_nread_no_pm (slave,SDW_SCP_INTSTAT2 ,2 , _buf2);if (ret <0 ) {dev_err (&slave->dev, -"SDW_SCP_INT2/3 read failed:%d\n" , ret); +"SDW_SCP_INT2/3 recheck read failed:%d\n" , ret); goto io_err; }
@@ -1613,7 +1613,7 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) ret =sdw_read_no_pm (slave,SDW_DP0_INT );if (ret <0 ) {dev_err (&slave->dev, -"SDW_DP0_INT read failed:%d\n" , ret); +"SDW_DP0_INT recheck read failed:%d\n" , ret); goto io_err; } sdca_cascade = ret &SDW_DP0_SDCA_CASCADE ;
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 6/11 soundwire: bus: remove useless initialization
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Cppcheck complains about a possible null pointer dereference, but it's more like there is an unnecessary initialization before walking through a list.
--- drivers/soundwire/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/bus.c +1 -1
@@ -593,7 +593,7 @@ EXPORT_SYMBOL(sdw_write);/* called with bus_lock held */ static struct sdw_slave *sdw_get_slave (struct sdw_bus *bus,int i) { -struct sdw_slave *slave =NULL ; +struct sdw_slave *slave;list_for_each_entry (slave, &bus->slaves, node) {if (slave->dev_num == i)
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 7/11 soundwire: generic_bandwidth_allocation: remove useless init
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Cppcheck complains about two possible null pointer dereferences, but it's more like there are unnecessary initializations before walking through a list.
--- drivers/soundwire/generic_bandwidth_allocation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soundwire/generic_bandwidth_allocation.c +2 -2
@@ -143,7 +143,7 @@ static void sdw_compute_master_ports(struct sdw_master_runtime *m_rt,static void _sdw_compute_port_params (struct sdw_bus *bus,struct sdw_group_params *params,int count) { -struct sdw_master_runtime *m_rt =NULL ; +struct sdw_master_runtime *m_rt;int hstop = bus->params.col -1 ;int block_offset, port_bo, i;
@@ -169,7 +169,7 @@ static int sdw_compute_group_params(struct sdw_bus *bus,struct sdw_group_params *params, int *rates, int count) { - struct sdw_master_runtime *m_rt = NULL; + struct sdw_master_runtime *m_rt;int sel_col = bus->params.col;unsigned int rate, bps, ch;int i, column_needed =0 ;
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 8/11 soundwire: intel: remove useless readl
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Cppcheck complains:
drivers/soundwire/intel.c:564:15: style: Variable 'link_control' is assigned a value that is never used. [unreadVariable]
link_control = intel_readl(shim, SDW_SHIM_LCTL);
This looks like a leftover from a previous version, remove.
--- drivers/soundwire/intel.c | 2 -- 1 file changed, 2 deletions(-)
drivers/soundwire/intel.c +0 -2
@@ -561,8 +561,6 @@ static int intel_link_power_down(struct sdw_intel *sdw) ret =intel_clear_bit (shim,SDW_SHIM_LCTL , link_control, cpa_mask); } - link_control =intel_readl (shim,SDW_SHIM_LCTL ); -mutex_unlock (sdw->link_res->shim_lock);if (ret <0 ) {
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 9/11 soundwire: qcom: check of_property_read status
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Cppcheck complains:
drivers/soundwire/qcom.c:773:6: style: Variable 'ret' is assigned a value that is never used. [unreadVariable]
ret = of_property_read_u8_array(np, "qcom,ports-block-pack-mode",
^
The return value is checked for all other cases, not sure why it was missed here.
--- drivers/soundwire/qcom.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/soundwire/qcom.c +3 -0
@@ -772,6 +772,9 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl) ret =of_property_read_u8_array (np,"qcom,ports-block-pack-mode" , bp_mode, nports); +if (ret) +return ret; +for (i =0 ; i < nports; i++) { ctrl->pconfig[i].si = si[i]; ctrl->pconfig[i].off1 = off1[i];
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 10/11 soundwire: stream: remove useless initialization
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Cppcheck complains about possible null pointer dereferences, but it's more like there are unnecessary initializations before walking through a list.
--- drivers/soundwire/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soundwire/stream.c +2 -2
@@ -261,7 +261,7 @@ static int sdw_program_master_port_params(struct sdw_bus *bus,*/ static int sdw_program_port_params (struct sdw_master_runtime *m_rt) { -struct sdw_slave_runtime *s_rt =NULL ; +struct sdw_slave_runtime *s_rt;struct sdw_bus *bus = m_rt->bus;struct sdw_port_runtime *p_rt;int ret =0 ;
@@ -1470,7 +1470,7 @@ static void sdw_acquire_bus_lock(struct sdw_stream_runtime *stream)*/ static void sdw_release_bus_lock (struct sdw_stream_runtime *stream) { -struct sdw_master_runtime *m_rt =NULL ; +struct sdw_master_runtime *m_rt;struct sdw_bus *bus =NULL ;/* Iterate for all Master(s) in Master list */
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH 11/11 soundwire: stream: remove useless bus initializations
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
There is no need to assign a pointer to NULL if it's only used in a loop and assigned within that loop.
--- drivers/soundwire/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soundwire/stream.c +2 -2
@@ -1449,7 +1449,7 @@ struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,static void sdw_acquire_bus_lock (struct sdw_stream_runtime *stream) {struct sdw_master_runtime *m_rt; -struct sdw_bus *bus =NULL ; +struct sdw_bus *bus;/* Iterate for all Master(s) in Master list */ list_for_each_entry (m_rt, &stream->master_list, stream_node) {
@@ -1471,7 +1471,7 @@ static void sdw_acquire_bus_lock(struct sdw_stream_runtime *stream)static void sdw_release_bus_lock (struct sdw_stream_runtime *stream) {struct sdw_master_runtime *m_rt; -struct sdw_bus *bus =NULL ; +struct sdw_bus *bus;/* Iterate for all Master(s) in Master list */ list_for_each_entry_reverse (m_rt, &stream->master_list, stream_node) {
Signature · 1 line
2.17.1
Quoted 1 line · Bard Liao
To make soundwire driver more decent and less Cppcheck complaint.
Applied all, thanks
Signature · 1 line
~Vinod