Re: [PATCH 09/17] soundwire: stream: remove unnecessary variable initializations

From: Pierre-Louis Bossart
Date: Tue Aug 06 2019 - 11:39:27 EST




On 8/6/19 10:31 AM, Cezary Rojewski wrote:
On 2019-08-06 02:55, Pierre-Louis Bossart wrote:
@@ -1493,6 +1493,11 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂ }
+ÂÂÂ if (!bus) {
+ÂÂÂÂÂÂÂ pr_err("Configuration error in %s\n", __func__);
+ÂÂÂÂÂÂÂ return -EINVAL;
+ÂÂÂ }
+

This should probably be located in separate path - not at all an initialization removal.

It's a consequence of the initialization removal: because we are removing the default init, there is a risk that the loop just before do not set it, so it's required to trap the case where the variable in not initialized.


@@ -1573,6 +1578,11 @@ static int _sdw_enable_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂ }
+ÂÂÂ if (!bus) {
+ÂÂÂÂÂÂÂ pr_err("Configuration error in %s\n", __func__);
+ÂÂÂÂÂÂÂ return -EINVAL;
+ÂÂÂ }
+

Same here.

same reply


@@ -1639,13 +1650,14 @@ static int _sdw_disable_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂ ret = do_bank_switch(stream);
ÂÂÂÂÂ if (ret < 0) {
-ÂÂÂÂÂÂÂ dev_err(bus->dev, "Bank switch failed: %d\n", ret);
+ÂÂÂÂÂÂÂ pr_err("Bank switch failed: %d\n", ret);
ÂÂÂÂÂÂÂÂÂ return ret;
ÂÂÂÂÂ }

Here too.

no, same thing, the bus variable is initialized in loops so tools will report a possible path where bus->dev is an invalid dereference.

I might have missed something though I bet you got my point.