Merge branch 'core-objtool-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / block / blk-zoned.c
index 05741c6f618be9162cf642faf83cbbc420023fe8..f87956e0dcafb315cac04254ea5e78162511a700 100644 (file)
 
 #include "blk.h"
 
+#define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name
+static const char *const zone_cond_name[] = {
+       ZONE_COND_NAME(NOT_WP),
+       ZONE_COND_NAME(EMPTY),
+       ZONE_COND_NAME(IMP_OPEN),
+       ZONE_COND_NAME(EXP_OPEN),
+       ZONE_COND_NAME(CLOSED),
+       ZONE_COND_NAME(READONLY),
+       ZONE_COND_NAME(FULL),
+       ZONE_COND_NAME(OFFLINE),
+};
+#undef ZONE_COND_NAME
+
+/**
+ * blk_zone_cond_str - Return string XXX in BLK_ZONE_COND_XXX.
+ * @zone_cond: BLK_ZONE_COND_XXX.
+ *
+ * Description: Centralize block layer function to convert BLK_ZONE_COND_XXX
+ * into string format. Useful in the debugging and tracing zone conditions. For
+ * invalid BLK_ZONE_COND_XXX it returns string "UNKNOWN".
+ */
+const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
+{
+       static const char *zone_cond_str = "UNKNOWN";
+
+       if (zone_cond < ARRAY_SIZE(zone_cond_name) && zone_cond_name[zone_cond])
+               zone_cond_str = zone_cond_name[zone_cond];
+
+       return zone_cond_str;
+}
+EXPORT_SYMBOL_GPL(blk_zone_cond_str);
+
 static inline sector_t blk_zone_start(struct request_queue *q,
                                      sector_t sector)
 {
@@ -173,7 +205,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
        if (!op_is_zone_mgmt(op))
                return -EOPNOTSUPP;
 
-       if (!nr_sectors || end_sector > capacity)
+       if (end_sector <= sector || end_sector > capacity)
                /* Out of range */
                return -EINVAL;