From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 347BD227BB5 for ; Sat, 28 Mar 2026 05:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774674183; cv=none; b=LAgw8w7dYBs7Kk/jtxKZ2tMbi7/x0TEQqY+Tcx23WCIjFD9jbHHgtQSc/N6j4hu9KA1r3nCEdRzPFTk0Kh3CnM6DJWyQgJIb/Qkpye6b4Spp7p7zYiJD/OipWUYNK1MCb8FB4SVSC8XzmHMSSdU/4LYvlnRIEmMFZCffcrUAVrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774674183; c=relaxed/simple; bh=RA9eUe+gnEl5B7sPzhN1dHV/pHppBGSxzQyy9oc1jC0=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=AO+NpJfIPMG/4u57jF+rHJ1qU18PZqDOUVilIDMqKYK7F6Jz7UMuHe68Xr04vK0ViEikuWi//Of3xwNXPilhw1jMSiJQy0Dx0V/YA+sHUrqKmT9b2Gb29+nm0TL6oTSR6grboY5Zzya+7vM/vknCLCX2XQawUY4F5QKBk88NDbE= 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=mTFe4i7S; arc=none smtp.client-ip=209.85.216.44 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="mTFe4i7S" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-354bc7c2c46so1729280a91.0 for ; Fri, 27 Mar 2026 22:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774674181; x=1775278981; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=H3JSX2pzaaiQjbe5Ws37SyQ0tu8pdJEZiAoEP2B3/gw=; b=mTFe4i7SKlzQM6f0p43jbOw81Ca8bt0jznl69GlzHA14pWTBfIH6qP4l74tZIdBumx d6WWHPUbRGFPSETTJsGgING5yhguKPGEBdk1zOfD2aiU6HzEWHe0C2TOrabh6WqjZk9C Knm9NyI7ZAo5rmFMcrIvrsywKhkUyaWa3dOX/h6/cQCia5mLX0B3uPtfifN03xhDMUkY CWNS1SMR82bGy7CQUp9PGjtdBs8OHp7CoRWfozCoJYREIQvYUEOA9Q1yI+vwyxYJER4t eksgqEX+nYl/nBKtluTCHYS1fSYgRGVVkw3i9gHwoO904YnXqYaR0fcFmUxH5dZQXOTa ZexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774674181; x=1775278981; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H3JSX2pzaaiQjbe5Ws37SyQ0tu8pdJEZiAoEP2B3/gw=; b=kn0vLBepLTc4aZqeGLtUA4s7DVJ1UCYng7Ltw5N9FLH1m63Yx6MiQwGiaK1iTEOPer o47e4X2Z6MQQOjv3Z0Zs8O5A+ftlqvgIoFCvMd5NyNF5pp79QySYv1awNOS0c9NSH8qg 40MNUpRqp9mHpuEwoK5fv/vcR8tpnnB7xMVPvyakRTc6Frnqv/ERaHNIIx6PouXKHB+N 4AN9tb7Ynu00wVdQxXWV0Qyg6rAeUZZkyeesAnbDT/RvcFXAwLRAT7na3dTzJeI8PPpP 4GzqhkZAXpjOb+jbPf3Hd5TPRn0+ezy9WNu16l/5nIJvWhsS3yPWMRmPqfyaBIRM5qmw PPIg== X-Forwarded-Encrypted: i=1; AJvYcCWf7T3MoOdvi+gDHeglzhHpyEzAVxXc/RyftdZWQkF9fDndihpA4Hh5ETg+66euhN7RrEQyz/LVaH8H+fA=@vger.kernel.org X-Gm-Message-State: AOJu0YxOPt8ZT9b/UHxUTE1jGebvY6osKGDBFHS3Adgc2w8lwV8rHP+L uZJCxNfCAmiJ51Q5vFV8g2ahmKe118LqbNb/9SDRrJWwK75dkdRTTYfA X-Gm-Gg: ATEYQzxjnf9WYQ4+gLSRVH49RmvCrCI2VTn1Qbn7G2hQKjwsh8jFJOEQclh0ikEXJA1 4oIuQmnsUQVnvF5mkbABP+YwTO4+xfwX3qngMAkJzaTVoX1Qh0v2DNF+W2e6DYBpigcJOBa3Mqs P7pvJysFKA9WzzyOKMnq60hiNfTNZ6mFEoFc+2KnEACZ6t5gYaiK3vioTSHg6hGH42NnTiU/bPy n0guYdgilbcbU2FhhDoKXO5l+Tlse7iekR2ySvHVmSum3NdVjrDoO1MQEYBCmYd0csroBT2zufg zpvTzz19KOjR9kX9G46dfJSpjY3qF4AFIwz6dIWfnqqEGyoD6LgKeEamFJEBlIp7i5hR5XIQJLD rNrCS03SKxs9kN8xfRMpuv1YURs10n9MG1bHEYfgR0viReORJWbVXE9KN0OhoNVajFr8iP/yXNs vkt8yDPo6teBkoiwF4FuGoFjMIwaRd4v9OYH3q5kOdQFNodQ== X-Received: by 2002:a17:90b:28c7:b0:35b:a3be:f1b6 with SMTP id 98e67ed59e1d1-35c30076d01mr5256174a91.16.1774674181275; Fri, 27 Mar 2026 22:03:01 -0700 (PDT) Received: from ehlo.thunderbird.net ([2401:4900:c009:ac88:99b7:137b:c894:2d7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35d9507dd72sm803914a91.12.2026.03.27.22.02.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Mar 2026 22:03:00 -0700 (PDT) Date: Sat, 28 Mar 2026 10:32:56 +0530 From: Sanjay Chitroda To: Andy Shevchenko CC: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, kees@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_v4_4/4=5D_iio=3A_ssp=5Fsensors=3A_reus?= =?US-ASCII?Q?e_preallocated_RX_buffer_for_SPI_transfers?= User-Agent: Thunderbird for Android In-Reply-To: References: <20260326081815.925373-1-sanjayembedded@gmail.com> <20260326081815.925373-5-sanjayembedded@gmail.com> Message-ID: <31B44DC6-FE3E-441D-94E2-DFADDAE7FA69@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 26 March 2026 2:55:49=E2=80=AFpm IST, Andy Shevchenko wrote: >On Thu, Mar 26, 2026 at 01:48:15PM +0530, Sanjay Chitroda wrote: > >> Avoid allocating a temporary DMA buffer in the interrupt context when >> handling hub-to-AP and AP-to-hub SPI write messages=2E >>=20 >> Preallocate RX buffer during probe and reuse it for SPI receive >> operations=2E This removes repeated kzalloc() calls from the IRQ >> path, reduces allocation overhead, and avoids potential allocation >> failures under memory pressure=2E >>=20 >> The RX buffer size is tracked and allocated using devm_kzalloc(), ensur= ing >> proper lifetime management tied to the device=2E >>=20 >> No functional change intended; this is an internal optimization and >> robustness improvement=2E > >NAK=2E > >=2E=2E=2E > >> @@ -512,6 +512,17 @@ static int ssp_probe(struct spi_device *spi) >> =20 >> mutex_init(&data->comm_lock); > >Pzzz! The wrong use of managed vs=2E unmanaged resources=2E > >> + data->rx_buf_size =3D SSP_DATA_PACKET_SIZE; >> + data->rx_buf =3D devm_kzalloc(&spi->dev, >> + data->rx_buf_size, >> + GFP_KERNEL | GFP_DMA); > >There are plenty of room on the previous lines=2E I think I already comme= nted on >something like this=2E > >> + > >This blank line is redundant=2E > >> + if (!data->rx_buf) { > >> + dev_err(&spi->dev, >> + "Failed to allocate memory for rx_buf\n"); > >Pzzz! >Have you read about error messages for -ENOMEM? Please, take your time an= d >study this case=2E > >> + return -ENOMEM; >> + } >> + >> for (i =3D 0; i < SSP_SENSOR_MAX; ++i) { >> data->delay_buf[i] =3D SSP_DEFAULT_POLLING_DELAY; >> data->batch_latency_buf[i] =3D 0; > > Thanks Andy for the review=2E I have addressed the comments related to this change and updated the alloc= ation as follows: data->rx_buf_size =3D SSP_DATA_PACKET_SIZE; data->rx_buf =3D devm_kzalloc(&spi->dev, data->rx_buf_size, GFP_KERNEL); if (!data->rx_buf) return -ENOMEM; Regarding the managed vs unmanaged resource comment =E2=80=94 since "struc= t ssp_data" is allocated using "devm_kzalloc()", I aligned "rx_buf" with th= e same lifetime=2E For the IRQ handling and other resource management aspects, I will address= those separately to keep this change focused=2E Please let me know if you would prefer those fixes to be included as part = of this patch=2E I will include these updates in the next revision=2E