partitions/ibm: Replace strncpy() and improve readability
authorJan Höppner <hoeppner@linux.ibm.com>
Fri, 15 Sep 2023 13:10:00 +0000 (15:10 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 4 Oct 2023 14:04:08 +0000 (08:04 -0600)
commitf5f43aae6f336ae436759144a31879375e65ed28
tree34f5311fe8ad7137444c7a68e36813b6f37d318d
parentd323c1a9477a82843795f10fb23f1634cea44007
partitions/ibm: Replace strncpy() and improve readability

strncpy() is deprecated and needs to be replaced. The volume label
information strings are not nul-terminated and strncpy() can simply be
replaced with memcpy().

To enhance the readability of find_label() alongside this change, the
following improvements are made:
- Introduce the array dasd_vollabels[] containing all information
  necessary for the label detection.
- Provide a helper function to obtain an index value corresponding to a
  volume label type. This allows the use of a switch statement to reduce
  indentation levels.
- The 'temp' variable is used to check against valid volume label types.
  In the good case, this variable already contains the volume label type
  making it unnecessary to copy the information again from e.g.
  label->vol.vollbl. Remove the 'temp' variable and the second copy as
  all information are already provided.
- Remove the 'found' variable and replace it with early returns

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Link: https://lore.kernel.org/r/20230915131001.697070-3-sth@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/partitions/ibm.c