NVMeBasicContext: Reject bad I2C bus IDs
We can't possibly query such sensors, so ensure they can't exist.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I899979db57a84272be9b537d87e54756296695cf
diff --git a/include/NVMeContext.hpp b/include/NVMeContext.hpp
index 27c1720..f8270f2 100644
--- a/include/NVMeContext.hpp
+++ b/include/NVMeContext.hpp
@@ -6,13 +6,20 @@
#include <boost/asio/io_service.hpp>
#include <memory>
+#include <stdexcept>
class NVMeContext : public std::enable_shared_from_this<NVMeContext>
{
public:
NVMeContext(boost::asio::io_service& io, int rootBus) :
scanTimer(io), rootBus(rootBus)
- {}
+ {
+ if (rootBus < 0)
+ {
+ throw std::invalid_argument(
+ "Invalid root bus: Bus ID must not be negative");
+ }
+ }
virtual ~NVMeContext()
{