public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] part: return -ENOSYS when get_info not valid.
@ 2021-10-19 13:35 zhaohui.shi
  2021-10-19 15:23 ` Heinrich Schuchardt
  0 siblings, 1 reply; 7+ messages in thread
From: zhaohui.shi @ 2021-10-19 13:35 UTC (permalink / raw)
  To: u-boot; +Cc: sjg, seanga2, schspa, xypron.glpk

From: schspa <schspa@gmail.com>

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

Signed-off-by: schspa <schspa@gmail.com>
---
 disk/part.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index a6a8f7052b..7af3240ec7 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -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) {
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] part: return -ENOSYS when get_info not valid.
@ 2021-10-19  8:17 schspa
  0 siblings, 0 replies; 7+ messages in thread
From: schspa @ 2021-10-19  8:17 UTC (permalink / raw)
  To: u-boot; +Cc: sjg, seanga2, schspa, xypron.glpk

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

Signed-off-by: schspa <schspa@gmail.com>
---
 disk/part.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index a6a8f7052b..7af3240ec7 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -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) {
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-20 12:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-19 13:35 [PATCH] part: return -ENOSYS when get_info not valid zhaohui.shi
2021-10-19 15:23 ` Heinrich Schuchardt
2021-10-20  2:37   ` schspa
2021-10-20  4:44     ` Heinrich Schuchardt
2021-10-20  5:54       ` schspa
2021-10-20  6:57         ` Heinrich Schuchardt
  -- strict thread matches above, loose matches on Subject: below --
2021-10-19  8:17 schspa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox