Hi Varada,

On 9/17/2026 2:49 PM, Varadarajan Narayanan wrote:
[...]

+static const char *fb_block_interface(void)
+{
+       if (!IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK))
+               return NULL;
+
+       if (block_interface_override[0])
+               return block_interface_override;
+
+       return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
+                                 CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME, 
NULL);
If CONFIG_FASTBOOT_FLASH_BLOCK was not enabled, the code wouldn't have
reached here. The first if check would have caught it. So a plain return
CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME would suffice.
I've removed the redundant IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK)
guards as suggested.

However, I kept config_opt_enabled() in the return path. While the
helpers are only called from CONFIG_FASTBOOT_FLASH_BLOCK-gated call
sites, fb_block.c is also built when CONFIG_FASTBOOT_FLASH_MMC is
enabled:

obj-$(CONFIG_FASTBOOT_FLASH_BLOCK) += fb_block.o
obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_block.o fb_mmc.o

In an MMC-only build,
CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME and
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID are not defined, so replacing
config_opt_enabled() with a direct return of those symbols causes a
compile failure.

config_opt_enabled() keeps the code compile-safe in that configuration,
while the redundant runtime guard can still be removed.
+}
+
+/**
+ * fb_block_device() - Resolve the block device number to use
+ *
+ * Returns the runtime override set via fastboot_block_set_target() if one
+ * is active, otherwise falls back to the build-time config default.
+ */
+static int fb_block_device(void)
+{
+       if (!IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK))
+               return -1;
+
+       if (block_device_override >= 0)
+               return block_device_override;
+
+       return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
+                                 CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID, -1);
+}
Same as above.

[...]

+static void __maybe_unused oem_set_block_target(char *cmd_parameter, char 
*response)
+{
+       char interface[16] = { 0 };
+       int device = -1;
+       char *space;
+
+       if (!cmd_parameter) {
+               fastboot_fail("Expected command parameter", response);
+               return;
+       }
+
+       space = strchr(cmd_parameter, ' ');
+       if (space) {
+               size_t len = space - cmd_parameter;
+
+               if (len >= sizeof(interface)) {
+                       fastboot_fail("interface name too long", response);
+                       return;
+               }
+               memcpy(interface, cmd_parameter, len);
+               interface[len] = '\0';
+               device = simple_strtoul(space + 1, NULL, 10);
simple_strtol since device is int?

Use simple_strtol() instead of simple_strtoul() when parsing the device ID.

Reject malformed and negative device IDs


Thanks,

Vandhiadevan


Thanks
Varada

[...]

Reply via email to