From a5dd3fa1e99ca8157f497a417b549711ea839eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 5 Jul 2016 09:39:15 +0200 Subject: [PATCH] ahci: make policy checking more fail-safe Handle cases where no policy is given and/or no policy matches. Fixes #2033. --- repos/os/src/drivers/ahci/main.cc | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/repos/os/src/drivers/ahci/main.cc b/repos/os/src/drivers/ahci/main.cc index e4374566a8..c5e6be1724 100644 --- a/repos/os/src/drivers/ahci/main.cc +++ b/repos/os/src/drivers/ahci/main.cc @@ -68,18 +68,28 @@ class Block::Root_multiple_clients : public Root_component< ::Session_component> Genode::Allocator &_alloc; Genode::Xml_node _config; + Xml_node _lookup_policy(char const *label) + { + for (Xml_node policy = _config.sub_node("policy");; + policy = policy.next("policy")) { + + char label_buf[64]; + policy.attribute("label").value(label_buf, sizeof(label_buf)); + + if (Genode::strcmp(label, label_buf) == 0) { + return policy; + } + } + + throw Xml_node::Nonexistent_sub_node(); + } + long _device_num(const char *session_label, char *model, char *sn, size_t bufs_len) { long num = -1; - Xml_node policy = _config.sub_node("policy"); - - for (;; policy = policy.next("policy")) { - char label_buf[64]; - policy.attribute("label").value(label_buf, sizeof(label_buf)); - - if (Genode::strcmp(session_label, label_buf)) - continue; + try { + Xml_node policy = _lookup_policy(session_label); /* try read device port number attribute */ try { @@ -92,8 +102,7 @@ class Block::Root_multiple_clients : public Root_component< ::Session_component> policy.attribute("model").value(model, bufs_len); policy.attribute("serial").value(sn, bufs_len); } catch (...) { } - break; - } + } catch (...) { } return num; }