scst: Use typed zeroed allocations for core objects and tests

Use the existing kzalloc_obj and kzalloc_objs helpers for PR abort state,
copy-manager list IDs, WRITE SAME state, latency statistics and UNMAP
fixtures. Drop the redundant default GFP_KERNEL argument in the ordering
fixture.

For single objects, the helper derives the allocation size from the
object expression. For arrays, keep the element count and checked
multiplication provided by the shared compatibility helper. Preserve
zeroing and explicit allocation flags, including the GFP_ATOMIC path.

These are allocation cleanups carried over from the historical analyzer
series; they do not fix an observed report-mode diagnostic in the
current Coccinelle run. No allocator model or exclusion is introduced.
This commit is contained in:
Gleb Chesnokov
2026-10-20 18:02:29 +03:00
parent aab41ff5a7
commit df688342dc
5 changed files with 7 additions and 8 deletions
@@ -38,7 +38,7 @@ static int order_test_init(struct kunit *test)
test->priv = NULL;
/* Workers may outlive a failed test; KUnit must not reclaim their state. */
f = kzalloc_obj(*f, GFP_KERNEL);
f = kzalloc_obj(*f);
if (!f)
return -ENOMEM;
if (!try_module_get(THIS_MODULE)) {
@@ -245,7 +245,7 @@ static void unmap_overlap(struct kunit *test)
KUNIT_ASSERT_EQ(test, f->unmap.cmd_data_descriptors_cnt, (int)p->count);
if (p->count) {
/* Bound the old sentinel walk without changing the published count. */
guarded = kcalloc(p->count + 2, sizeof(*guarded), GFP_KERNEL);
guarded = kzalloc_objs(*guarded, p->count + 2);
KUNIT_ASSERT_NOT_NULL(test, guarded);
memcpy(guarded, f->unmap.cmd_data_descriptors, p->count * sizeof(*guarded));
if (p->guard_overlap) {
+1 -1
View File
@@ -1891,7 +1891,7 @@ static struct scst_cm_list_id *scst_cm_add_list_id(struct scst_cmd *cmd, int lis
TRACE_ENTRY();
res = kzalloc(sizeof(*res), GFP_KERNEL);
res = kzalloc_obj(*res);
if (!res) {
TRACE(TRACE_OUT_OF_MEM, "Unable to allocate list_id");
scst_set_busy(cmd);
+3 -4
View File
@@ -6790,8 +6790,7 @@ static int scst_ws_sg_tails_get(struct scst_data_descriptor *where, struct scst_
while (where[i].sdd_blocks != 0)
i++;
wsp->ws_sg_tails = kcalloc(i + 1, sizeof(*wsp->ws_sg_tails),
GFP_KERNEL);
wsp->ws_sg_tails = kzalloc_objs(*wsp->ws_sg_tails, i + 1);
if (wsp->ws_sg_tails == NULL) {
PRINT_ERROR("Unable to allocate ws_sg_tails (size %zd)",
sizeof(*wsp->ws_sg_tails)*i);
@@ -6870,7 +6869,7 @@ void scst_write_same(struct scst_cmd *cmd, struct scst_data_descriptor *where)
if (unlikely(rc != 0))
goto out_done;
wsp = kzalloc(sizeof(*wsp), GFP_KERNEL);
wsp = kzalloc_obj(*wsp);
if (wsp == NULL) {
PRINT_ERROR("Unable to allocate ws_priv (size %zd, cmd %p)",
sizeof(*wsp), cmd);
@@ -7416,7 +7415,7 @@ struct scst_session *scst_alloc_session(struct scst_tgt *tgt, gfp_t gfp_mask,
* for the GFP_ATOMIC case.
*/
sess->lat_stats = gfp_mask & GFP_ATOMIC ?
kzalloc(sizeof(*sess->lat_stats), gfp_mask) :
kzalloc_obj(*sess->lat_stats, gfp_mask) :
vzalloc(sizeof(*sess->lat_stats));
if (!sess->lat_stats)
goto out_free_name;
+1 -1
View File
@@ -2254,7 +2254,7 @@ void scst_pr_preempt_and_abort(struct scst_cmd *cmd, uint8_t *buffer, int buffer
scst_assert_pr_mutex_held(cmd->dev);
cmd->pr_abort_counter = kzalloc(sizeof(*cmd->pr_abort_counter), GFP_KERNEL);
cmd->pr_abort_counter = kzalloc_obj(*cmd->pr_abort_counter);
if (!cmd->pr_abort_counter) {
PRINT_ERROR("Unable to allocate PR abort counter (size %zd)",
sizeof(*cmd->pr_abort_counter));