Skip to contentSkip to conversation

staging: greybus: change mutexes to guard macros

PATCH In review Omer PALA 4 participants 8 messages Sep 20

Subsystems (8)
lore
Share & tools
lore

Omer PALA

author
#0 lore raw

PATCH 1/1 staging: greybus: change mutexes to guard macros

Convert mutex_lock()/mutex_unlock() pairs to the guard() and scoped_guard() cleanup helpers where possible. This removes error-prone goto-based unlock paths and makes it harder to forget to release a mutex on an early return.

---
 drivers/staging/greybus/arche-platform.c | 29 +++----
 drivers/staging/greybus/audio_codec.c    | 97 ++++++++++--------------
 drivers/staging/greybus/audio_helper.c   |  3 +-
 drivers/staging/greybus/audio_topology.c | 10 +--
 drivers/staging/greybus/authentication.c | 34 ++++-----
 drivers/staging/greybus/bootrom.c        | 11 ++-
 drivers/staging/greybus/camera.c         | 60 +++++++--------
 drivers/staging/greybus/fw-download.c    | 31 ++++----
 drivers/staging/greybus/fw-management.c  | 38 ++++------
 drivers/staging/greybus/light.c          | 44 +++++------
 drivers/staging/greybus/loopback.c       | 39 +++++-----
 drivers/staging/greybus/power_supply.c   | 42 ++++------
 drivers/staging/greybus/raw.c            | 25 +++---
 drivers/staging/greybus/sdio.c           | 25 +++---
 drivers/staging/greybus/uart.c           | 30 +++-----
 15 files changed, 216 insertions(+), 302 deletions(-)
drivers/staging/greybus/arche-platform.c +10 -19
index de5de59ea..02322fce0 100644
@@ -310,20 +310,19 @@ static ssize_t state_store(struct device *dev,
 	struct arche_platform_drvdata *arche_pdata = dev_get_drvdata(dev);
 	int ret = 0;
 
-	mutex_lock(&arche_pdata->platform_state_mutex);
+	guard(mutex)(&arche_pdata->platform_state_mutex);
 
 	if (sysfs_streq(buf, "off")) {
 		if (arche_pdata->state == ARCHE_PLATFORM_STATE_OFF)
-			goto exit;
+			return count;
 
 		/*  If SVC goes down, bring down APB's as well */
 		device_for_each_child(arche_pdata->dev, NULL, apb_poweroff);
 
 		arche_platform_poweroff_seq(arche_pdata);
-
 	} else if (sysfs_streq(buf, "active")) {
 		if (arche_pdata->state == ARCHE_PLATFORM_STATE_ACTIVE)
-			goto exit;
+			return count;
 
 		/* First we want to make sure we power off everything
 		 * and then activate back again
@@ -334,16 +333,15 @@ static ssize_t state_store(struct device *dev,
 		arche_platform_wd_irq_en(arche_pdata);
 		ret = arche_platform_coldboot_seq(arche_pdata);
 		if (ret)
-			goto exit;
-
+			return ret;
 	} else if (sysfs_streq(buf, "standby")) {
 		if (arche_pdata->state == ARCHE_PLATFORM_STATE_STANDBY)
-			goto exit;
+			return count;
 
 		dev_warn(arche_pdata->dev, "standby state not supported\n");
 	} else if (sysfs_streq(buf, "fw_flashing")) {
 		if (arche_pdata->state == ARCHE_PLATFORM_STATE_FW_FLASHING)
-			goto exit;
+			return count;
 
 		/*
 		 * Here we only control SVC.
@@ -356,15 +354,11 @@ static ssize_t state_store(struct device *dev,
 
 		ret = arche_platform_fw_flashing_seq(arche_pdata);
 		if (ret)
-			goto exit;
+			return ret ? ret : count;
 	} else {
 		dev_err(arche_pdata->dev, "unknown state\n");
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-exit:
-	mutex_unlock(&arche_pdata->platform_state_mutex);
-	return ret ? ret : count;
 }
 
 static ssize_t state_show(struct device *dev,
@@ -396,7 +390,7 @@ static int arche_platform_pm_notifier(struct notifier_block *notifier,
 			     pm_notifier);
 	int ret = NOTIFY_DONE;
 
-	mutex_lock(&arche_pdata->platform_state_mutex);
+	guard(mutex)(&arche_pdata->platform_state_mutex);
 	switch (pm_event) {
 	case PM_SUSPEND_PREPARE:
 		if (arche_pdata->state != ARCHE_PLATFORM_STATE_ACTIVE) {
@@ -416,7 +410,6 @@ static int arche_platform_pm_notifier(struct notifier_block *notifier,
 	default:
 		break;
 	}
-	mutex_unlock(&arche_pdata->platform_state_mutex);
 
 	return ret;
 }
@@ -530,15 +523,13 @@ static int arche_platform_probe(struct platform_device *pdev)
 
 	/* Explicitly power off if requested */
 	if (!of_property_read_bool(pdev->dev.of_node, "arche,init-off")) {
-		mutex_lock(&arche_pdata->platform_state_mutex);
+		guard(mutex)(&arche_pdata->platform_state_mutex);
 		ret = arche_platform_coldboot_seq(arche_pdata);
 		if (ret) {
-			mutex_unlock(&arche_pdata->platform_state_mutex);
 			dev_err(dev, "Failed to cold boot svc %d\n", ret);
 			goto err_unregister_pm_notifier;
 		}
 		arche_platform_wd_irq_en(arche_pdata);
-		mutex_unlock(&arche_pdata->platform_state_mutex);
 	}
 
 	dev_info(dev, "Device registered successfully\n");
drivers/staging/greybus/audio_codec.c +39 -58

262 lines not on this page · raw message

drivers/staging/greybus/audio_helper.c +1 -2
index b4873c6d6..eeb2ca7a5 100644
@@ -117,7 +117,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
 	struct snd_soc_dapm_widget *w, *tmp_w;
 	struct snd_soc_card *card = snd_soc_dapm_to_card(dapm);
 
-	mutex_lock(&card->dapm_mutex);
+	guard(mutex)(&card->dapm_mutex);
 	for (i = 0; i < num; i++) {
 		/* below logic can be optimized to identify widget pointer */
 		w = NULL;
@@ -137,7 +137,6 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
 		widget++;
 		gbaudio_dapm_free_widget(w);
 	}
-	mutex_unlock(&card->dapm_mutex);
 	return 0;
 }
 
drivers/staging/greybus/audio_topology.c +4 -6
index 76146f91c..295625a48 100644
@@ -33,14 +33,12 @@ static struct gbaudio_module_info *find_gb_module(struct gbaudio_codec_info *cod
 
 	dev_dbg(codec->dev, "%s:Find module#%d\n", __func__, dev_id);
 
-	mutex_lock(&codec->lock);
-	list_for_each_entry(module, &codec->module_list, list) {
-		if (module->dev_id == dev_id) {
-			mutex_unlock(&codec->lock);
-			return module;
+	scoped_guard(mutex, &codec->lock) {
+		list_for_each_entry(module, &codec->module_list, list) {
+			if (module->dev_id == dev_id)
+				return module;
 		}
 	}
-	mutex_unlock(&codec->lock);
 	dev_warn(codec->dev, "%s: module#%d missing in codec list\n", name,
 		 dev_id);
 	return NULL;
drivers/staging/greybus/authentication.c +15 -19
index d8f2cd432..5c0bfc9b0 100644
@@ -65,20 +65,17 @@ static struct gb_cap *get_cap(struct cdev *cdev)
 {
 	struct gb_cap *cap;
 
-	mutex_lock(&list_mutex);
+	guard(mutex)(&list_mutex);
 
 	list_for_each_entry(cap, &cap_list, node) {
 		if (&cap->cdev == cdev) {
 			kref_get(&cap->kref);
-			goto unlock;
+			return cap;
 		}
 	}
 
 	cap = NULL;
 
-unlock:
-	mutex_unlock(&list_mutex);
-
 	return cap;
 }
 
@@ -276,7 +273,7 @@ static long cap_ioctl_unlocked(struct file *file, unsigned int cmd,
 	 * the connection is getting disconnected, so that we don't start any
 	 * new operations.
 	 */
-	mutex_lock(&cap->mutex);
+	guard(mutex)(&cap->mutex);
 	if (!cap->disabled) {
 		ret = gb_pm_runtime_get_sync(bundle);
 		if (!ret) {
@@ -284,7 +281,6 @@ static long cap_ioctl_unlocked(struct file *file, unsigned int cmd,
 			gb_pm_runtime_put_autosuspend(bundle);
 		}
 	}
-	mutex_unlock(&cap->mutex);
 
 	return ret;
 }
@@ -314,9 +310,9 @@ int gb_cap_connection_init(struct gb_connection *connection)
 	gb_connection_set_data(connection, cap);
 	kref_init(&cap->kref);
 
-	mutex_lock(&list_mutex);
-	list_add(&cap->node, &cap_list);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_add(&cap->node, &cap_list);
+	}
 
 	ret = gb_connection_enable(connection);
 	if (ret)
@@ -353,9 +349,9 @@ int gb_cap_connection_init(struct gb_connection *connection)
 err_connection_disable:
 	gb_connection_disable(connection);
 err_list_del:
-	mutex_lock(&list_mutex);
-	list_del(&cap->node);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_del(&cap->node);
+	}
 
 	put_cap(cap);
 
@@ -379,17 +375,17 @@ void gb_cap_connection_exit(struct gb_connection *connection)
 	 * Disallow any new ioctl operations on the char device and wait for
 	 * existing ones to finish.
 	 */
-	mutex_lock(&cap->mutex);
-	cap->disabled = true;
-	mutex_unlock(&cap->mutex);
+	scoped_guard(mutex, &cap->mutex) {
+		cap->disabled = true;
+	}
 
 	/* All pending greybus operations should have finished by now */
 	gb_connection_disable(cap->connection);
 
 	/* Disallow new users to get access to the cap structure */
-	mutex_lock(&list_mutex);
-	list_del(&cap->node);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_del(&cap->node);
+	}
 
 	/*
 	 * All current users of cap would have taken a reference to it by
drivers/staging/greybus/bootrom.c +8 -3
index 83921d90c..923456d6c 100644
@@ -78,9 +78,9 @@ static void gb_bootrom_timedout(struct work_struct *work)
 
 	dev_err(dev, "Timed out waiting for %s from the Module\n", reason);
 
-	mutex_lock(&bootrom->mutex);
-	free_firmware(bootrom);
-	mutex_unlock(&bootrom->mutex);
+	scoped_guard(mutex, &bootrom->mutex) {
+		free_firmware(bootrom);
+	}
 
 	/* TODO: Power-off Module ? */
 }
@@ -240,6 +240,11 @@ static int gb_bootrom_firmware_size_request(struct gb_operation *op)
 
 static int gb_bootrom_get_firmware(struct gb_operation *op)
 {
+	/*
+	 * Keep explicit mutex_lock/unlock here instead of guard(mutex)
+	 * to release the lock before queue_work.
+	 */
+
 	struct gb_bootrom *bootrom = gb_connection_get_data(op->connection);
 	const struct firmware *fw;
 	struct gb_bootrom_get_firmware_request *firmware_request;
drivers/staging/greybus/camera.c +28 -32

115 lines not on this page · raw message

drivers/staging/greybus/fw-download.c +13 -18
index a0a683447..a4e2e2361 100644
@@ -93,21 +93,16 @@ static struct fw_request *get_fw_req(struct fw_download *fw_download,
 {
 	struct fw_request *fw_req;
 
-	mutex_lock(&fw_download->mutex);
+	guard(mutex)(&fw_download->mutex);
 
 	list_for_each_entry(fw_req, &fw_download->fw_requests, node) {
 		if (fw_req->firmware_id == firmware_id) {
 			kref_get(&fw_req->kref);
-			goto unlock;
+			return fw_req;
 		}
 	}
 
-	fw_req = NULL;
-
-unlock:
-	mutex_unlock(&fw_download->mutex);
-
-	return fw_req;
+	return NULL;
 }
 
 static void free_firmware(struct fw_download *fw_download,
@@ -117,9 +112,9 @@ static void free_firmware(struct fw_download *fw_download,
 	if (fw_req->disabled)
 		return;
 
-	mutex_lock(&fw_download->mutex);
-	list_del(&fw_req->node);
-	mutex_unlock(&fw_download->mutex);
+	scoped_guard(mutex, &fw_download->mutex) {
+		list_del(&fw_req->node);
+	}
 
 	fw_req->disabled = true;
 	put_fw_req(fw_req);
@@ -197,9 +192,9 @@ static struct fw_request *find_firmware(struct fw_download *fw_download,
 	fw_req->fw_download = fw_download;
 	kref_init(&fw_req->kref);
 
-	mutex_lock(&fw_download->mutex);
-	list_add(&fw_req->node, &fw_download->fw_requests);
-	mutex_unlock(&fw_download->mutex);
+	scoped_guard(mutex, &fw_download->mutex) {
+		list_add(&fw_req->node, &fw_download->fw_requests);
+	}
 
 	/* Timeout, in jiffies, within which firmware should get loaded */
 	req_count = DIV_ROUND_UP(fw_req->fw->size, MIN_FETCH_SIZE);
@@ -448,10 +443,10 @@ void gb_fw_download_connection_exit(struct gb_connection *connection)
 	 * Make sure we have a reference to the pending requests, before they
 	 * are freed from the timeout handler.
 	 */
-	mutex_lock(&fw_download->mutex);
-	list_for_each_entry(fw_req, &fw_download->fw_requests, node)
-		kref_get(&fw_req->kref);
-	mutex_unlock(&fw_download->mutex);
+	scoped_guard(mutex, &fw_download->mutex) {
+		list_for_each_entry(fw_req, &fw_download->fw_requests, node)
+			kref_get(&fw_req->kref);
+	}
 
 	/* Release pending firmware packages */
 	list_for_each_entry_safe(fw_req, tmp, &fw_download->fw_requests, node) {
drivers/staging/greybus/fw-management.c +16 -22
index 5d01da6b6..c48bea217 100644
@@ -87,21 +87,16 @@ static struct fw_mgmt *get_fw_mgmt(struct cdev *cdev)
 {
 	struct fw_mgmt *fw_mgmt;
 
-	mutex_lock(&list_mutex);
+	guard(mutex)(&list_mutex);
 
 	list_for_each_entry(fw_mgmt, &fw_mgmt_list, node) {
 		if (&fw_mgmt->cdev == cdev) {
 			kref_get(&fw_mgmt->kref);
-			goto unlock;
+			return fw_mgmt;
 		}
 	}
 
-	fw_mgmt = NULL;
-
-unlock:
-	mutex_unlock(&list_mutex);
-
-	return fw_mgmt;
+	return NULL;
 }
 
 static int fw_mgmt_interface_fw_version_operation(struct fw_mgmt *fw_mgmt,
@@ -533,7 +528,7 @@ static long fw_mgmt_ioctl_unlocked(struct file *file, unsigned int cmd,
 	 * the connection is getting disconnected, so that we don't start any
 	 * new operations.
 	 */
-	mutex_lock(&fw_mgmt->mutex);
+	guard(mutex)(&fw_mgmt->mutex);
 	if (!fw_mgmt->disabled) {
 		ret = gb_pm_runtime_get_sync(bundle);
 		if (!ret) {
@@ -541,7 +536,6 @@ static long fw_mgmt_ioctl_unlocked(struct file *file, unsigned int cmd,
 			gb_pm_runtime_put_autosuspend(bundle);
 		}
 	}
-	mutex_unlock(&fw_mgmt->mutex);
 
 	return ret;
 }
@@ -591,9 +585,9 @@ int gb_fw_mgmt_connection_init(struct gb_connection *connection)
 	mutex_init(&fw_mgmt->mutex);
 	kref_init(&fw_mgmt->kref);
 
-	mutex_lock(&list_mutex);
-	list_add(&fw_mgmt->node, &fw_mgmt_list);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_add(&fw_mgmt->node, &fw_mgmt_list);
+	}
 
 	ret = gb_connection_enable(connection);
 	if (ret)
@@ -631,9 +625,9 @@ int gb_fw_mgmt_connection_init(struct gb_connection *connection)
 err_connection_disable:
 	gb_connection_disable(connection);
 err_list_del:
-	mutex_lock(&list_mutex);
-	list_del(&fw_mgmt->node);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_del(&fw_mgmt->node);
+	}
 
 	put_fw_mgmt(fw_mgmt);
 
@@ -657,17 +651,17 @@ void gb_fw_mgmt_connection_exit(struct gb_connection *connection)
 	 * Disallow any new ioctl operations on the char device and wait for
 	 * existing ones to finish.
 	 */
-	mutex_lock(&fw_mgmt->mutex);
-	fw_mgmt->disabled = true;
-	mutex_unlock(&fw_mgmt->mutex);
+	scoped_guard(mutex, &fw_mgmt->mutex) {
+		fw_mgmt->disabled = true;
+	}
 
 	/* All pending greybus operations should have finished by now */
 	gb_connection_disable(fw_mgmt->connection);
 
 	/* Disallow new users to get access to the fw_mgmt structure */
-	mutex_lock(&list_mutex);
-	list_del(&fw_mgmt->node);
-	mutex_unlock(&list_mutex);
+	scoped_guard(mutex, &list_mutex) {
+		list_del(&fw_mgmt->node);
+	}
 
 	/*
 	 * All current users of fw_mgmt would have taken a reference to it by
drivers/staging/greybus/light.c +18 -26

123 lines not on this page · raw message

drivers/staging/greybus/loopback.c +17 -22
index 2a623fc2e..2ca6d5c5f 100644
@@ -406,24 +406,22 @@ static void gb_loopback_async_operation_callback(struct gb_operation *operation)
 	op_async = gb_operation_get_data(operation);
 	gb = op_async->gb;
 
-	mutex_lock(&gb->mutex);
+	scoped_guard(mutex, &gb->mutex) {
+		if (!result && op_async->completion)
+			result = op_async->completion(op_async);
 
-	if (!result && op_async->completion)
-		result = op_async->completion(op_async);
+		if (!result) {
+			gb->elapsed_nsecs = gb_loopback_calc_latency(op_async->ts, te);
+		} else {
+			gb->error++;
+			if (result == -ETIMEDOUT)
+				gb->requests_timedout++;
+		}
 
-	if (!result) {
-		gb->elapsed_nsecs = gb_loopback_calc_latency(op_async->ts, te);
-	} else {
-		gb->error++;
-		if (result == -ETIMEDOUT)
-			gb->requests_timedout++;
+		gb->iteration_count++;
+		gb_loopback_calculate_stats(gb, result);
 	}
 
-	gb->iteration_count++;
-	gb_loopback_calculate_stats(gb, result);
-
-	mutex_unlock(&gb->mutex);
-
 	dev_dbg(&gb->connection->bundle->dev, "complete operation %d\n",
 		operation->id);
 
@@ -848,7 +846,7 @@ static int gb_loopback_fn(void *data)
 			gb_loopback_async_wait_all(gb);
 
 			/* Mark complete unless user-space has poked us */
-			mutex_lock(&gb->mutex);
+			guard(mutex)(&gb->mutex);
 			if (gb->iteration_count == gb->iteration_max) {
 				gb->type = 0;
 				gb->send_count = 0;
@@ -859,7 +857,6 @@ static int gb_loopback_fn(void *data)
 				dev_dbg(&bundle->dev,
 					"continuing on with new test set\n");
 			}
-			mutex_unlock(&gb->mutex);
 			continue;
 		}
 		size = gb->size;
@@ -919,18 +916,16 @@ static int gb_loopback_dbgfs_latency_show_common(struct seq_file *s,
 	int retval;
 
 	if (kfifo_len(kfifo) == 0) {
-		retval = -EAGAIN;
-		goto done;
+		return -EAGAIN;
 	}
 
-	mutex_lock(mutex);
+	guard(mutex)(mutex);
 	retval = kfifo_out(kfifo, &latency, sizeof(latency));
 	if (retval > 0) {
 		seq_printf(s, "%u", latency);
-		retval = 0;
+		return 0;
 	}
-	mutex_unlock(mutex);
-done:
+
 	return retval;
 }
 
drivers/staging/greybus/power_supply.c +16 -26

123 lines not on this page · raw message

drivers/staging/greybus/raw.c +10 -15
index 4f1b3f4db..b280b5b75 100644
@@ -246,12 +246,12 @@ static void gb_raw_disconnect(struct gb_bundle *bundle)
 	gb_connection_disable(connection);
 	gb_connection_destroy(connection);
 
-	mutex_lock(&raw->list_lock);
-	list_for_each_entry_safe(raw_data, temp, &raw->list, entry) {
-		list_del(&raw_data->entry);
-		kfree(raw_data);
+	scoped_guard(mutex, &raw->list_lock) {
+		list_for_each_entry_safe(raw_data, temp, &raw->list, entry) {
+			list_del(&raw_data->entry);
+			kfree(raw_data);
+		}
 	}
-	mutex_unlock(&raw->list_lock);
 	put_device(&raw->dev);
 }
 
@@ -310,19 +310,16 @@ static ssize_t raw_read(struct file *file, char __user *buf, size_t count,
 	int retval = 0;
 	struct raw_data *raw_data;
 
-	mutex_lock(&raw->list_lock);
+	guard(mutex)(&raw->list_lock);
 	if (list_empty(&raw->list))
-		goto exit;
+		return 0;
 
 	raw_data = list_first_entry(&raw->list, struct raw_data, entry);
-	if (raw_data->len > count) {
-		retval = -ENOSPC;
-		goto exit;
-	}
+	if (raw_data->len > count)
+		return -ENOSPC;
 
 	if (copy_to_user(buf, &raw_data->data[0], raw_data->len)) {
-		retval = -EFAULT;
-		goto exit;
+		return -EFAULT;
 	}
 
 	list_del(&raw_data->entry);
@@ -330,8 +327,6 @@ static ssize_t raw_read(struct file *file, char __user *buf, size_t count,
 	retval = raw_data->len;
 	kfree(raw_data);
 
-exit:
-	mutex_unlock(&raw->list_lock);
 	return retval;
 }
 
drivers/staging/greybus/sdio.c +9 -16
index 3952f3d22..316aaeb15 100644
@@ -597,7 +597,7 @@ static void gb_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	u8 drv_type;
 	u32 vdd = 0;
 
-	mutex_lock(&host->lock);
+	guard(mutex)(&host->lock);
 	request.clock = cpu_to_le32(ios->clock);
 
 	if (ios->vdd)
@@ -710,24 +710,19 @@ static void gb_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 
 	ret = gb_sdio_set_ios(host, &request);
 	if (ret < 0)
-		goto out;
+		return;
 
 	memcpy(&mmc->ios, ios, sizeof(mmc->ios));
-
-out:
-	mutex_unlock(&host->lock);
 }
 
 static int gb_mmc_get_ro(struct mmc_host *mmc)
 {
 	struct gb_sdio_host *host = mmc_priv(mmc);
 
-	mutex_lock(&host->lock);
+	guard(mutex)(&host->lock);
 	if (host->removed) {
-		mutex_unlock(&host->lock);
 		return -ESHUTDOWN;
 	}
-	mutex_unlock(&host->lock);
 
 	return host->read_only;
 }
@@ -736,12 +731,10 @@ static int gb_mmc_get_cd(struct mmc_host *mmc)
 {
 	struct gb_sdio_host *host = mmc_priv(mmc);
 
-	mutex_lock(&host->lock);
+	guard(mutex)(&host->lock);
 	if (host->removed) {
-		mutex_unlock(&host->lock);
 		return -ESHUTDOWN;
 	}
-	mutex_unlock(&host->lock);
 
 	return host->card_present;
 }
@@ -852,11 +845,11 @@ static void gb_sdio_remove(struct gbphy_device *gbphy_dev)
 	if (ret)
 		gbphy_runtime_get_noresume(gbphy_dev);
 
-	mutex_lock(&host->lock);
-	host->removed = true;
-	mmc = host->mmc;
-	gb_connection_set_data(connection, NULL);
-	mutex_unlock(&host->lock);
+	scoped_guard(mutex, &host->lock) {
+		host->removed = true;
+		mmc = host->mmc;
+		gb_connection_set_data(connection, NULL);
+	}
 
 	destroy_workqueue(host->mrq_workqueue);
 	gb_connection_disable_rx(connection);
drivers/staging/greybus/uart.c +12 -18
index 24b4dab06..e1aa12966 100644
@@ -341,19 +341,16 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 {
 	struct gb_tty *gb_tty;
 
-	mutex_lock(&table_lock);
+	guard(mutex)(&table_lock);
 	gb_tty = idr_find(&tty_minors, minor);
 	if (gb_tty) {
-		mutex_lock(&gb_tty->mutex);
+		guard(mutex)(&gb_tty->mutex);
 		if (gb_tty->disconnected) {
-			mutex_unlock(&gb_tty->mutex);
 			gb_tty = NULL;
 		} else {
 			tty_port_get(&gb_tty->port);
-			mutex_unlock(&gb_tty->mutex);
 		}
 	}
-	mutex_unlock(&table_lock);
 	return gb_tty;
 }
 
@@ -361,9 +358,9 @@ static int alloc_minor(struct gb_tty *gb_tty)
 {
 	int minor;
 
-	mutex_lock(&table_lock);
-	minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
-	mutex_unlock(&table_lock);
+	scoped_guard(mutex, &table_lock) {
+		minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
+	}
 	if (minor >= 0)
 		gb_tty->minor = minor;
 	return minor;
@@ -374,9 +371,8 @@ static void release_minor(struct gb_tty *gb_tty)
 	int minor = gb_tty->minor;
 
 	gb_tty->minor = 0;	/* Maybe should use an invalid value instead */
-	mutex_lock(&table_lock);
+	guard(mutex)(&table_lock);
 	idr_remove(&tty_minors, minor);
-	mutex_unlock(&table_lock);
 }
 
 static int gb_tty_install(struct tty_driver *driver, struct tty_struct *tty)
@@ -596,13 +592,12 @@ static int get_serial_info(struct tty_struct *tty,
 	struct gb_tty *gb_tty = tty->driver_data;
 
 	ss->line = gb_tty->minor;
-	mutex_lock(&gb_tty->port.mutex);
+	guard(mutex)(&gb_tty->port.mutex);
 	ss->close_delay = jiffies_to_msecs(gb_tty->port.close_delay) / 10;
 	ss->closing_wait =
 		gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
 		ASYNC_CLOSING_WAIT_NONE :
 		jiffies_to_msecs(gb_tty->port.closing_wait) / 10;
-	mutex_unlock(&gb_tty->port.mutex);
 
 	return 0;
 }
@@ -620,7 +615,7 @@ static int set_serial_info(struct tty_struct *tty,
 			ASYNC_CLOSING_WAIT_NONE :
 			msecs_to_jiffies(ss->closing_wait * 10);
 
-	mutex_lock(&gb_tty->port.mutex);
+	guard(mutex)(&gb_tty->port.mutex);
 	if (!capable(CAP_SYS_ADMIN)) {
 		if ((close_delay != gb_tty->port.close_delay) ||
 		    (closing_wait != gb_tty->port.closing_wait))
@@ -629,7 +624,6 @@ static int set_serial_info(struct tty_struct *tty,
 		gb_tty->port.close_delay = close_delay;
 		gb_tty->port.closing_wait = closing_wait;
 	}
-	mutex_unlock(&gb_tty->port.mutex);
 	return retval;
 }
 
@@ -926,11 +920,11 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
 	if (ret)
 		gbphy_runtime_get_noresume(gbphy_dev);
 
-	mutex_lock(&gb_tty->mutex);
-	gb_tty->disconnected = true;
+	scoped_guard(mutex, &gb_tty->mutex) {
+		gb_tty->disconnected = true;
 
-	wake_up_all(&gb_tty->wioctl);
-	mutex_unlock(&gb_tty->mutex);
+		wake_up_all(&gb_tty->wioctl);
+	}
 
 	tty_port_tty_vhangup(&gb_tty->port);
 
Signature · 1 line
2.55.0
#1 lore raw
Quoted 6 lines · Omer PALA

Convert mutex_lock()/mutex_unlock() pairs to the guard() and scoped_guard() cleanup helpers where possible. This removes error-prone goto-based unlock paths and makes it harder to forget to release a mutex on an early return.

Did you miss the review comments I made for the previous patch like this a few hours ago:

	https://lore.kernel.org/all/2026092014-despair-secular-d579@gregkh/

?

author
#2 lore raw

Hi Greg,

I thought someone (not you) can allow this.

I want to contribute kernel but i dont know what should i do.

I wrote 3 devicetree schemas, 2 performance fixes, 2 mutex/spinlock fixes and 1 syntax fix.

All of my work got NAK.

Can you explain me what should i do?

Best Regards,
Omer PALA

#3 lore raw
Quoted 9 lines · Omer PALA

Hi Greg,

I thought someone (not you) can allow this.

I want to contribute kernel but i dont know what should i do.

I wrote 3 devicetree schemas, 2 performance fixes, 2 mutex/spinlock fixes and 1 syntax fix.

Quoted 6 lines

All of my work got NAK.

Can you explain me what should i do?

Best Regards,
Omer PALA

Hi, I don't tend to jump into staging threads, because well I don't do staging and all that, but I'm sure I can help you here.

From me looking in archives, you tend to use AI tools, which isn't allowed in staging as of right now.

Staging is a learners playground, not a AI bot bug report thing.

If you need any help you can contact me off list any time you need it, I do need to start mentoring people....

Quoted 2 lines

--- Thanks!
"I'm not a very positive person" - Linus torvalds

#4 lore raw
In reply to Omer PALA
Quoted 4 lines · Omer PALA

Hi Greg,

I thought someone (not you) can allow this.

Quoted 8 lines

I want to contribute kernel but i dont know what should i do.

I wrote 3 devicetree schemas, 2 performance fixes, 2 mutex/spinlock fixes and 1 syntax fix.

All of my work got NAK.

Can you explain me what should i do?

Try to contribute "normal" coding style cleanups for staging drivers, ones that you know will be correct (because you can verify them), and NOT used with any LLM tool.

thanks,

greg k-h

#5 lore raw
In reply to Omer PALA
Quoted 3 lines · Omer PALA

Hi Greg,

I thought someone (not you) can allow this.

So you received feedback from Greg, but tried on different part, hoping this time it will get accepted?

This looks similar to you previous approaches, e.g. for DT bindings, where you received comments and repeated the same thing immediately. Three or four time.

Quoted 2 lines

I want to contribute kernel but i dont know what should i do.

I suggest spend some time to actually read the archives when people point it.

Quoted 5 lines

I wrote 3 devicetree schemas, 2 performance fixes, 2 mutex/spinlock fixes and 1 syntax fix.

All of my work got NAK.

One was pure AI slop, so what did you expect exactly? In all channels, fediverse, some technological news, open source projects complain about sent slop, they reject it and treat it as one of biggest time wasting thing contributor could do. It is not like we hide it, right? Actually opposite, everywhere we scream - don't send vibe coded stuff. And for learning or beginning this is even unacceptable waste of your time, because you will learn nothing. I was raising it for GSoC for example more than once and it is documented in their rules.

Quoted 2 lines

Can you explain me what should i do?

One idea would be to read more before you actually contribute.

Best regards,
Krzysztof

#6 lore raw
Quoted 35 lines · Krzysztof Kozlowski
Quoted 3 lines · Omer PALA

Hi Greg,

I thought someone (not you) can allow this.

So you received feedback from Greg, but tried on different part, hoping this time it will get accepted?

This looks similar to you previous approaches, e.g. for DT bindings, where you received comments and repeated the same thing immediately. Three or four time.

Quoted 2 lines

I want to contribute kernel but i dont know what should i do.

I suggest spend some time to actually read the archives when people point it.

Quoted 5 lines

I wrote 3 devicetree schemas, 2 performance fixes, 2 mutex/spinlock fixes and 1 syntax fix.

All of my work got NAK.

One was pure AI slop, so what did you expect exactly? In all channels, fediverse, some technological news, open source projects complain about sent slop, they reject it and treat it as one of biggest time wasting thing contributor could do. It is not like we hide it, right? Actually opposite, everywhere we scream - don't send vibe coded stuff. And for learning or beginning this is even unacceptable waste of your time, because you will learn nothing. I was raising it for GSoC for example more than once and it is documented in their rules.

Quoted 1 line
Quoted 3 lines
Quoted 1 line

Can you explain me what should i do?

One idea would be to read more before you actually contribute.

... and if you even asked your AI like I did now:
"how linux kernel developers look at LLM contributions from beginners?" I got:

"Linux kernel developers view unverified AI-generated code from beginners with heavy skepticism and frustration due to a massive influx of low-quality submissions that overwhelm maintainers."

"Rejection of AI "slop": "

"Staging area bans: Certain high-traffic areas prone to beginner contributions, such as the kernel's staging drivers (drivers/staging/), have implemented strict policies forbidding LLM-generated patches ...."

Yet you did exactly what should not be done - were using LLM.

Best regards,
Krzysztof

author
#7 lore raw
Quoted 11 lines · Krzysztof Kozlowski

... and if you even asked your AI like I did now:
"how linux kernel developers look at LLM contributions from beginners?" I got:

"Linux kernel developers view unverified AI-generated code from beginners with heavy skepticism and frustration due to a massive influx of low-quality submissions that overwhelm maintainers."

"Rejection of AI "slop": "

Quoted 8 lines

"Staging area bans: Certain high-traffic areas prone to beginner contributions, such as the kernel's staging drivers (drivers/staging/), have implemented strict policies forbidding LLM-generated patches ...."

Yet you did exactly what should not be done - were using LLM.

Best regards,
Krzysztof

Hi Greg and Krzystof

I didn't use AI to generate this code. It took 5-6 hours.

I don't know why you said I used LLM to generate this such code.

Quoted 6 lines · Krzystof

So you received feedback from Greg, but tried on different part, hoping this time it will get accepted?

This looks similar to you previous approaches, e.g. for DT bindings, where you received comments and repeated the same thing immediately. Three or four time.

I generally write 2 or 3 patches and send them parallelly. I won't do this again.

I thought fixing some spaghetti code and changing mutex_lock/mutex_unlock to guard macros is fine.

Best Regards,
Omer PALA