From 423ad8144697363f270bee1c3a67cd80a6b20f9a Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Mon, 27 Apr 2020 13:32:27 +1000 Subject: [PATCH] LU-6142 lustre: Remove inappropriate uses of BIT() macro. The BIT() macro exists for identifying a specific bit in a word when it is being used as a bitmap (or mask for set of flags etc). While it uses "1 << ...." it is not a general replacement for that construct and should not be used to simply to raise '2' to some power. Varous places in lustre and libcfs use BIT() when a size, rather than a BIT, are required. Convert these to explicitly use "1 << exponent". Test-Parameters: trivial Signed-off-by: Mr NeilBrown Change-Id: I41e1e188da4d2e5dff5b2c05cec607c1d104bcfa Reviewed-on: https://review.whamcloud.com/38373 Tested-by: jenkins Reviewed-by: Olaf Faaland-LLNL Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/libcfs/module.c | 7 ++++--- lustre/ldlm/ldlm_resource.c | 9 +++------ lustre/llite/lproc_llite.c | 38 +++++++++++++++++++------------------- lustre/obdclass/class_obd.c | 11 ++++++----- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 8b165cc..c51b493 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -73,13 +73,14 @@ static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) static bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) { - if (data->ioc_hdr.ioc_len > BIT(30)) + const int maxlen = 1 << 30; + if (data->ioc_hdr.ioc_len > maxlen) return true; - if (data->ioc_inllen1 > BIT(30)) + if (data->ioc_inllen1 > maxlen) return true; - if (data->ioc_inllen2 > BIT(30)) + if (data->ioc_inllen2 > maxlen) return true; if (data->ioc_inlbuf1 && !data->ioc_inllen1) diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 1bb742c..5410fb1 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -880,8 +880,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, ns->ns_bucket_bits = ldlm_ns_hash_defs[ns_type].nsd_all_bits - ldlm_ns_hash_defs[ns_type].nsd_bkt_bits; - OBD_ALLOC_LARGE(ns->ns_rs_buckets, - BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0])); + OBD_ALLOC_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits); if (!ns->ns_rs_buckets) goto out_hash; @@ -951,8 +950,7 @@ out_sysfs: ldlm_namespace_sysfs_unregister(ns); ldlm_namespace_cleanup(ns, 0); out_hash: - OBD_FREE_LARGE(ns->ns_rs_buckets, - BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0])); + OBD_FREE_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits); kfree(ns->ns_name); cfs_hash_putref(ns->ns_rs_hash); out_ns: @@ -1221,8 +1219,7 @@ void ldlm_namespace_free_post(struct ldlm_namespace *ns) ldlm_namespace_debugfs_unregister(ns); ldlm_namespace_sysfs_unregister(ns); cfs_hash_putref(ns->ns_rs_hash); - OBD_FREE_LARGE(ns->ns_rs_buckets, - BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0])); + OBD_FREE_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits); kfree(ns->ns_name); /* Namespace \a ns should be not on list at this time, otherwise * this will cause issues related to using freed \a ns in poold diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 3bb3de6..6f90377 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1759,26 +1759,26 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, write_tot += pp_info->pp_w_hist.oh_buckets[i]; } - for(i = 0; i < LL_HIST_MAX; i++) { - r = pp_info->pp_r_hist.oh_buckets[i]; - w = pp_info->pp_w_hist.oh_buckets[i]; - read_cum += r; - write_cum += w; - end = BIT(i + LL_HIST_START - units); + for(i = 0; i < LL_HIST_MAX; i++) { + r = pp_info->pp_r_hist.oh_buckets[i]; + w = pp_info->pp_w_hist.oh_buckets[i]; + read_cum += r; + write_cum += w; + end = 1 << (i + LL_HIST_START - units); seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u | " "%14lu %4u %4u\n", start, *unitp, end, *unitp, - (i == LL_HIST_MAX - 1) ? '+' : ' ', - r, pct(r, read_tot), pct(read_cum, read_tot), - w, pct(w, write_tot), pct(write_cum, write_tot)); - start = end; - if (start == BIT(10)) { - start = 1; - units += 10; - unitp++; - } - if (read_cum == read_tot && write_cum == write_tot) - break; - } + (i == LL_HIST_MAX - 1) ? '+' : ' ', + r, pct(r, read_tot), pct(read_cum, read_tot), + w, pct(w, write_tot), pct(write_cum, write_tot)); + start = end; + if (start == (1 << 10)) { + start = 1; + units += 10; + unitp++; + } + if (read_cum == read_tot && write_cum == write_tot) + break; + } } static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v) @@ -1939,7 +1939,7 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist); } - for (i = 0; (count >= BIT(LL_HIST_START + i)) && + for (i = 0; (count >= 1 << (LL_HIST_START + i)) && (i < (LL_HIST_MAX - 1)); i++); if (rw == 0) { io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++; diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 3871d32..a399698 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -134,27 +134,28 @@ out: static int obd_ioctl_is_invalid(struct obd_ioctl_data *data) { - if (data->ioc_len > BIT(30)) { + const int maxlen = 1 << 30; + if (data->ioc_len > maxlen) { CERROR("OBD ioctl: ioc_len larger than 1<<30\n"); return 1; } - if (data->ioc_inllen1 > BIT(30)) { + if (data->ioc_inllen1 > maxlen) { CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n"); return 1; } - if (data->ioc_inllen2 > BIT(30)) { + if (data->ioc_inllen2 > maxlen) { CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n"); return 1; } - if (data->ioc_inllen3 > BIT(30)) { + if (data->ioc_inllen3 > maxlen) { CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n"); return 1; } - if (data->ioc_inllen4 > BIT(30)) { + if (data->ioc_inllen4 > maxlen) { CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n"); return 1; } -- 1.8.3.1