Commit Graph

3 Commits

Author SHA1 Message Date
Shuo A Liu 3e0b06cfd6 dm: Fix some issues from string operations
The patch fix some string operations issues and also improve readability
of several snippet.

Tracked-On: #2133
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2018-12-25 18:40:04 +08:00
Jie Deng 7579678dd6 dm: add const declaration for dm_strto* APIs
These APIs are wrap of standard strto* APIs. The first parameters in
these APIs should be declared as "const" since they have never been
changed so that they can also be used when passing a variable declared
as const char *

Fixes: e1dab512c2 ("dm: add string convert API")
Tracked-on: #1496

Signed-off-by: Jie Deng <jie.deng@intel.com>
Reviewed-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-24 18:16:37 +08:00
Conghui Chen e1dab512c2 dm: add string convert API
As function sscanf is banned, to get value from parameter buffer,strto*
is recommended. To reduce the inspection code when using strto*, it's
better to use a string convert API.

Usage:
    For virtio-blk, it has parameters:
        range=<start lba>/<subfile size>
    sscanf:
        if (sscanf(cp, "range=%ld/%ld", &sub_file_start_lba,
                &sub_file_size) == 2)
            sub_file_assign = 1;
    string API:
        if (strsep(&cp, "=") &&
                !dm_strtol(cp, &cp, 10, &sub_file_start_lba) &&
                *cp == '/' &&
                !dm_strtol(cp + 1, &cp, 10, &sub_file_size))
            sub_file_assign = 1;

Tracked-on: #1496
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2018-10-17 16:22:00 +08:00