[PATCH 14/14] Fixed the retry_cnt bug about being zero

Kiseok Jo kiseok.jo at irondevice.com
Fri Jan 6 10:15:43 CET 2023


Signed-off-by: Kiseok Jo <kiseok.jo at irondevice.com>
Reported-by: kernel test robot <lkp at intel.com>
Reported-by: Dan Carpenter <error27 at gmail.com>
---
 sound/soc/codecs/sma1303.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/sound/soc/codecs/sma1303.c b/sound/soc/codecs/sma1303.c
index 1a5d992bf3db..4f9dab5d1613 100644
--- a/sound/soc/codecs/sma1303.c
+++ b/sound/soc/codecs/sma1303.c
@@ -247,7 +247,7 @@ EXPORT_SYMBOL(sma1303_set_callback_func);
 static int sma1303_regmap_write(struct sma1303_priv *sma1303,
 				unsigned int reg, unsigned int val)
 {
-	int ret;
+	int ret = 0;
 	int cnt = sma1303->retry_cnt;
 
 	while (cnt--) {
@@ -266,7 +266,7 @@ static int sma1303_regmap_write(struct sma1303_priv *sma1303,
 static int sma1303_regmap_update_bits(struct sma1303_priv *sma1303,
 		unsigned int reg, unsigned int mask, unsigned int val)
 {
-	int ret;
+	int ret = 0;
 	int cnt = sma1303->retry_cnt;
 
 	while (cnt--) {
@@ -285,7 +285,7 @@ static int sma1303_regmap_update_bits(struct sma1303_priv *sma1303,
 static int sma1303_regmap_read(struct sma1303_priv *sma1303,
 			unsigned int reg, unsigned int *val)
 {
-	int ret;
+	int ret = 0;
 	int cnt = sma1303->retry_cnt;
 
 	while (cnt--) {
@@ -772,12 +772,13 @@ static int sma1303_add_component_controls(struct snd_soc_component *component)
 	sma1303_controls = devm_kzalloc(sma1303->dev,
 			sizeof(sma1303_snd_controls), GFP_KERNEL);
 	name = devm_kzalloc(sma1303->dev,
-			ARRAY_SIZE(sma1303_snd_controls), GFP_KERNEL);
+			ARRAY_SIZE(sma1303_snd_controls)*sizeof(char *),
+			GFP_KERNEL);
 
 	for (index = 0; index < ARRAY_SIZE(sma1303_snd_controls); index++) {
 		sma1303_controls[index] = sma1303_snd_controls[index];
 		name[index] = devm_kzalloc(sma1303->dev,
-				MAX_CONTROL_NAME, GFP_KERNEL);
+				MAX_CONTROL_NAME*sizeof(char), GFP_KERNEL);
 		size = strlen(sma1303_snd_controls[index].name)
 			+ strlen(sma1303->dev->driver->name);
 		if (!name[index] || size > MAX_CONTROL_NAME) {
@@ -1544,7 +1545,7 @@ static int sma1303_i2c_probe(struct i2c_client *client,
 	struct sma1303_priv *sma1303;
 	struct device_node *np = client->dev.of_node;
 	int ret, i = 0;
-	u32 value;
+	u32 value = 0;
 	unsigned int device_info, status, otp_stat;
 
 	sma1303 = devm_kzalloc(&client->dev,
@@ -1564,13 +1565,13 @@ static int sma1303_i2c_probe(struct i2c_client *client,
 
 	if (np) {
 		if (!of_property_read_u32(np, "i2c-retry", &value)) {
-			if (value > 50 || value < 0) {
+			if (value > 50 || value <= 0) {
 				sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT;
 				dev_info(&client->dev, "%s : %s\n", __func__,
 					"i2c-retry out of range (up to 50)");
 			} else {
 				sma1303->retry_cnt = value;
-				dev_info(&client->dev, "%s : %s = %d\n",
+				dev_info(&client->dev, "%s : %s = %u\n",
 					__func__, "i2c-retry count", value);
 			}
 		} else {
@@ -1589,7 +1590,7 @@ static int sma1303_i2c_probe(struct i2c_client *client,
 		}
 		if (!of_property_read_u32(np, "tdm-slot-tx", &value)) {
 			dev_info(&client->dev,
-				"tdm slot tx is '%d' from DT\n", value);
+				"tdm slot tx is '%u' from DT\n", value);
 			sma1303->tdm_slot_tx = value;
 		} else {
 			dev_info(&client->dev,
@@ -1609,7 +1610,7 @@ static int sma1303_i2c_probe(struct i2c_client *client,
 				break;
 			default:
 				dev_err(&client->dev,
-					"Invalid sys-clk-id: %d\n", value);
+					"Invalid sys-clk-id: %u\n", value);
 				return -EINVAL;
 			}
 			sma1303->sys_clk_id = value;
-- 
2.30.2



More information about the Alsa-devel mailing list