Skip to contentSkip to conversation

part: return -ENOSYS when get_info not valid.

PATCH New schspa 1 participant 1 message Oct 19, 2021

lore
Share & tools
lore

schspa

author
#0 lore raw

PATCH 1/1 part: return -ENOSYS when get_info not valid.

In some case, get_info() interface can be NULL, add this check to stop from crash.

---
 disk/part.c | 7 +++++++
 1 file changed, 7 insertions(+)
disk/part.c +7 -0
index a6a8f7052b..7af3240ec7 100644
@@ -668,6 +668,13 @@ int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
 	part_drv = part_driver_lookup_type(dev_desc);
 	if (!part_drv)
 		return -1;
+
+	if (!part_drv->get_info) {
+		PRINTF("## Driver %s does not have the get_info() method\n",
+		       part_drv->name);
+		return -ENOSYS;
+	}
+
 	for (i = 1; i < part_drv->max_entries; i++) {
 		ret = part_drv->get_info(dev_desc, i, info);
 		if (ret != 0) {
Signature · 1 line
2.33.1