From patchwork Mon Jun 17 02:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 13699898 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B07AC16C6AF for ; Mon, 17 Jun 2024 02:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718590350; cv=none; b=YCEL6AP+BUbP3x+m59J2ifY14ykbFx/Xj9F1b4/cwfslALzxW3bVXATJ28XFlOTMHROshBQ8sy/FEDnmemLgECRQlisqH/hxG7fbI60tqek5yJG9ymmHrgalwlHHPLNTgNsifpSjuKMJBCcujOFYK4sxi+1C4PdObm6d+gLba7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718590350; c=relaxed/simple; bh=+usWI0nPBVcSZ+VJqjI6qxc97XtNV3HNm04/jAf8hVI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PrAU7o8NqDQGTyH2vpBjvVY6XDL6xkwElawA0nQXZDEUH2fNiaU9SmHjcf04bERv0EOfyKPUo7YAvnTtw9wCF6dTjmEQqH/BP4HEzHOan7gzM2Y+1v3YNwwRNdXLgBEvtfEWyHaRnUKKvBebMPW2jU4rk2TWBhJ9BawGVbt9ulM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=o4WMaMkL; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="o4WMaMkL" X-Envelope-To: markus.elfring@web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718590344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M8Qv5NrmpUkXbkH01JqmIrt+CGtlE3ZyafHTyGTEsUw=; b=o4WMaMkL0QujctNqCm7RhryIdoRkf0PTp9GQGVMPAhXSCijgB7iL0Y7gYHo3Kms3AFAfDi eaw1Hp1SElrC4zXpNQPyvz6BshqW8odKK+UhcApS0mnUI4SFwsBb0CHWaIlsqf65Q80k2v SKGNGWCALfJESUs7QLj/dHLeFJSgyRQ= X-Envelope-To: broonie@kernel.org X-Envelope-To: perex@perex.cz X-Envelope-To: tiwai@suse.com X-Envelope-To: shenghao-ding@ti.com X-Envelope-To: colin.i.king@gmail.com X-Envelope-To: gehao618@163.com X-Envelope-To: linux-sound@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: gehao@kylinos.cn X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Ge To: Markus.Elfring@web.de, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: shenghao-ding@ti.com, colin.i.king@gmail.com, gehao618@163.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Hao Ge Subject: [PATCH v2] ASoc: PCM6240: Return directly after a failed devm_kzalloc() in pcmdevice_i2c_probe() Date: Mon, 17 Jun 2024 10:09:54 +0800 Message-Id: <20240617020954.17252-1-hao.ge@linux.dev> In-Reply-To: <82283abf-10b1-4095-a93f-112ba8aca483@web.de> References: <82283abf-10b1-4095-a93f-112ba8aca483@web.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT From: Hao Ge The value “-ENOMEM” was assigned to the local variable “ret” in one if branch after a devm_kzalloc() call failed at the beginning. This error code will trigger then a pcmdevice_remove() call with a passed null pointer so that an undesirable dereference will be performed. Thus return the appropriate error code directly. Fixes: 1324eafd37aa ("ASoc: PCM6240: Create PCM6240 Family driver code") Signed-off-by: Hao Ge --- v2: - adjust title and commit message - omit curly brackets --- sound/soc/codecs/pcm6240.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c index 86e126783a1d..8f7057e689fb 100644 --- a/sound/soc/codecs/pcm6240.c +++ b/sound/soc/codecs/pcm6240.c @@ -2087,10 +2087,8 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c) #endif pcm_dev = devm_kzalloc(&i2c->dev, sizeof(*pcm_dev), GFP_KERNEL); - if (!pcm_dev) { - ret = -ENOMEM; - goto out; - } + if (!pcm_dev) + return -ENOMEM; pcm_dev->chip_id = (id != NULL) ? id->driver_data : 0;