habanalabs: use strscpy instead of sprintf and strlcpy
authorOded Gabbay <ogabbay@kernel.org>
Sat, 3 Apr 2021 13:37:29 +0000 (16:37 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Fri, 9 Apr 2021 11:09:24 +0000 (14:09 +0300)
Prefer the use of strscpy when copying the ASIC name into a char array,
to prevent accidentally exceeding the array's length.
In addition, strlcpy is frowned upon so replace it.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/device.c

index e64c60d48d421bd554a2e81491d237f86b0fa650..2ed4f2bedc08aee0f7e87ae91264537fe08ed636 100644 (file)
@@ -321,11 +321,11 @@ static int device_early_init(struct hl_device *hdev)
        switch (hdev->asic_type) {
        case ASIC_GOYA:
                goya_set_asic_funcs(hdev);
-               strlcpy(hdev->asic_name, "GOYA", sizeof(hdev->asic_name));
+               strscpy(hdev->asic_name, "GOYA", sizeof(hdev->asic_name));
                break;
        case ASIC_GAUDI:
                gaudi_set_asic_funcs(hdev);
-               sprintf(hdev->asic_name, "GAUDI");
+               strscpy(hdev->asic_name, "GAUDI", sizeof(hdev->asic_name));
                break;
        default:
                dev_err(hdev->dev, "Unrecognized ASIC type %d\n",