From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D880823EAA0 for ; Mon, 11 May 2026 23:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778541213; cv=none; b=egqtOxOfI3gEn63G6F0O4sAbEVZnICVOp00HUqeNN9qRoMBzHSGFeHHD/YG7qDjP9Me96SbrmrjdcVaVI1T2T5vhsB96UWEMjdz7+vTGItQjk3qv6wiJc4V2j5OCQIlxplmsMM1hlWXBxg2xqmNtXNTdqKt8uNSkB6YbCbOfI6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778541213; c=relaxed/simple; bh=lyut248ohL8lMiQjhMEr4em5gqDx1XiavnPgwudBiiY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=X6vyFG2NcKG3bJWqm8H8zDkUTwzosW2GurhEgZtunssGepo4C4NXhVJizm/M/zodno+TzDsgvP0WmGFvRqqau0u9mgUvo7nI5naqAh6VgrJi8/xQAfrj6GPyYMf7Ds1wtWWiIf0oYoN6fWs7XVq2EcdONgtOkMQJ/mKlmZMWRfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WRrwrcnK; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WRrwrcnK" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-366330b6751so3122615a91.1 for ; Mon, 11 May 2026 16:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778541211; x=1779146011; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lFgRqIfPnwsr89P7tCB0q0/8N2KZaaQUIqXtzxlp1YE=; b=WRrwrcnKO3PCPK/MKwI7Ku0rHvDItL7Mdtv0aHQi1Zn2UFIc/aUX3zGsr6G6qePixX 3hPio+d5cVPjYhh5UskHCbUdMEXUeg5x1qT6msMzeFOl7HIJEHCVjmD1FBeJFBrMJw/X 6+JMtHf7ltkUMt4NQhQ0fyEF2UG/OvnH2uQ9NmG9qTwMHpjPkRx5DlJSHEwuAQqJ5axF 5nzusuddMw1E4OwgXZzQtyWjLxbGUm3+MtfhJ77jAeiULkucvnDscZYFvAq7Mz56rLMF eO5EyEdwRfckgsFyupL+LzEzNYYVnty1ViAe0yEX50GVymAtoNMOg6uIEV3GnXl1ys87 DlRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778541211; x=1779146011; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lFgRqIfPnwsr89P7tCB0q0/8N2KZaaQUIqXtzxlp1YE=; b=gZ4DFCWViFQBB6PZ+8bAu6AyGlxEOoI5viz5P/r/IYq+gdB3vQD43ghVLDh32n4jMc NDRyBAezo4OduDlVbKoEXNDo9CS2LBs0xMCL7cmUSiOpgcVzCIENpl2x77IjjxLJnqqx vEBHcLD8BCv9UPlT/ZAO3rq6oYRE18t5GmDgBEn0jibGF0n2ocWqNNZL9lxccydEC6qL seQmE6ZBldOW1sgbn0I0LTtI52VBxvl2+sR+ZJSg+COpCt8TpxSOYEomO1TyomkuF+aF GrygzcImwDHQD8iZf7/vaehhkoM153llp4zB64fXKx2ggZz/o9pcr59RG2yVmVQiBqRh ospw== X-Forwarded-Encrypted: i=1; AFNElJ95gstA5cjh2mYX246Mrt5CDHnEMHJogwTQ5r0phk1e09Rw9Bjxkhj6YIGt82SlH1PjhvXCc5s28uDgjwg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8j3AkM1egt6He0Vv504uAOdKcqScF4sOLMINXyxu+Zs05QTC6 BdDZxChDS9xYKOPg4YGwRppA3vBZAJlQE1CkCT7w08GDcxTKagosgQsR X-Gm-Gg: Acq92OERdyw1UEXxHmQ4RDSiFj66zDp80U4PMMgjsdx1MQNzD/VoegfseGA0hVsgwDa FgN8bB5rLt83bk2DWLrrdMEPej8A0Xj/6+FhC0Ln7VUlC17sp//v450vgidcZY8AuippFSTIWPN +NKTfh/ZAlKII51RFy8CmLSNhed0vJMNUqzSDhNLk9QKvHTc4t1tykpPhxLIMhrINLthssFtKo8 /5/yF+/zaeacykGPAzFCj3g8S8LJta3E+z85zk6tOJ2TL8FkWKwIEbKh1O92F05OJEo1/mZADsi ksEbe0gb8av3/Thbqe6tYqOgQSRyZpafE9PlLgx4NBihf0DApCQXFzgCUCsfPJiphvmDsQ9BRQU 0CdE/DYNkQfl/cs2Ox1xiQwtm1MOYS4Rh3oDYSXn9P5ISF4MJQ2Ej5xlxlH5Szf5nXTl69beNyZ mduO6tX+XIUDOvsm1m8RRWaG6sEZEpxb1gx79hA+fQOkPEDqW+vMV/Bzn6YMRqVrWwzkHsDmm2X ApjILd7k2fn6ibatSIyLAnVmqIrYymga48W2TRtYtRx4g== X-Received: by 2002:a17:90b:578d:b0:35f:b5df:450 with SMTP id 98e67ed59e1d1-365ac2807f0mr26507247a91.19.1778541211167; Mon, 11 May 2026 16:13:31 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d623f7bcsm8839486a91.4.2026.05.11.16.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 16:13:30 -0700 (PDT) From: Rosen Penev To: linux-sound@vger.kernel.org Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] ASoC: pcm6240: Use flexible array for config blocks Date: Mon, 11 May 2026 16:13:13 -0700 Message-ID: <20260511231313.31929-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Store the per-config block pointer table in the config allocation instead of allocating it separately. This ties the table to the config object lifetime and removes the extra allocation and free path. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev --- sound/soc/codecs/pcm6240.c | 36 +++++++++++++++--------------------- sound/soc/codecs/pcm6240.h | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c index 78b21fbfad50..667596fc1781 100644 --- a/sound/soc/codecs/pcm6240.c +++ b/sound/soc/codecs/pcm6240.c @@ -1230,15 +1230,11 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, int *status) { struct pcmdevice_priv *pcm_dev = (struct pcmdevice_priv *)ctxt; - struct pcmdevice_config_info *cfg_info; + struct pcmdevice_config_info *cfg_info = NULL; struct pcmdevice_block_data **bk_da; + char cfg_name[64] = {}; unsigned int config_offset = 0, i; - - cfg_info = kzalloc_obj(struct pcmdevice_config_info); - if (!cfg_info) { - *status = -ENOMEM; - goto out; - } + unsigned int nblocks; if (pcm_dev->regbin.fw_hdr.binary_version_num >= 0x105) { if (config_offset + 64 > (int)config_size) { @@ -1247,7 +1243,7 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, "%s: cfg_name out of boundary\n", __func__); goto out; } - memcpy(cfg_info->cfg_name, &config_data[config_offset], 64); + memcpy(cfg_name, &config_data[config_offset], 64); config_offset += 64; } @@ -1257,16 +1253,17 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, __func__); goto out; } - cfg_info->nblocks = - get_unaligned_be32(&config_data[config_offset]); + nblocks = get_unaligned_be32(&config_data[config_offset]); config_offset += 4; - bk_da = cfg_info->blk_data = kzalloc_objs(struct pcmdevice_block_data *, - cfg_info->nblocks); - if (!bk_da) { + cfg_info = kzalloc_flex(*cfg_info, blk_data, nblocks); + if (!cfg_info) { *status = -ENOMEM; goto out; } + cfg_info->nblocks = nblocks; + memcpy(cfg_info->cfg_name, cfg_name, sizeof(cfg_info->cfg_name)); + bk_da = cfg_info->blk_data; cfg_info->real_nblocks = 0; for (i = 0; i < cfg_info->nblocks; i++) { if (config_offset + 12 > config_size) { @@ -1449,14 +1446,11 @@ static void pcmdevice_config_info_remove(void *ctxt) for (i = 0; i < regbin->ncfgs; i++) { if (!cfg_info[i]) continue; - if (cfg_info[i]->blk_data) { - for (j = 0; j < (int)cfg_info[i]->real_nblocks; j++) { - if (!cfg_info[i]->blk_data[j]) - continue; - kfree(cfg_info[i]->blk_data[j]->regdata); - kfree(cfg_info[i]->blk_data[j]); - } - kfree(cfg_info[i]->blk_data); + for (j = 0; j < (int)cfg_info[i]->real_nblocks; j++) { + if (!cfg_info[i]->blk_data[j]) + continue; + kfree(cfg_info[i]->blk_data[j]->regdata); + kfree(cfg_info[i]->blk_data[j]); } kfree(cfg_info[i]); } diff --git a/sound/soc/codecs/pcm6240.h b/sound/soc/codecs/pcm6240.h index 2d8f9e798139..e27afd33910c 100644 --- a/sound/soc/codecs/pcm6240.h +++ b/sound/soc/codecs/pcm6240.h @@ -199,7 +199,7 @@ struct pcmdevice_config_info { unsigned int nblocks; unsigned int real_nblocks; unsigned char active_dev; - struct pcmdevice_block_data **blk_data; + struct pcmdevice_block_data *blk_data[] __counted_by(nblocks); }; struct pcmdevice_regbin { -- 2.54.0