From 85df0de4cfe54fd64df7e37448cd152d0c9199a4 Mon Sep 17 00:00:00 2001 From: blueswir1 Date: Thu, 11 Dec 2008 17:30:50 +0000 Subject: [PATCH] Allow to register a callback with fw_cfg_add_callback() fw_cfg_add_callback() checks if key has FW_CFG_WRITE_CHANNEL bit set after masking the key with FW_CFG_ENTRY_MASK. But as FW_CFG_ENTRY_MASK is ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL), the bit is never set and function exits. This patch corrects this by checking the bit before masking the value. Signed-by-off: Laurent Vivier Acked-by: Gleb Natapov git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5978 c046a42c-6fe2-441c-8c8c-71466251a162 --- hw/fw_cfg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c index 4e686702a3..4333ed9fbd 100644 --- a/hw/fw_cfg.c +++ b/hw/fw_cfg.c @@ -240,10 +240,12 @@ int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback, FWCfgState *s = opaque; int arch = !!(key & FW_CFG_ARCH_LOCAL); + if (!(key & FW_CFG_WRITE_CHANNEL)) + return 0; + key &= FW_CFG_ENTRY_MASK; - if (key >= FW_CFG_MAX_ENTRY || !(key & FW_CFG_WRITE_CHANNEL) - || len > 65535) + if (key >= FW_CFG_MAX_ENTRY || len > 65535) return 0; s->entries[arch][key].data = data;