Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp271636lqt; Thu, 6 Jun 2024 03:11:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTg8Vsh8KqODvUoFw6j2jjiwoedFju0ZxLbGotOeqAgcDrwJ49S1OKFklB/oVv96bQUdL9yXS8l4tkKO+JNm14DjdDKOdp/kDsjcmX4Q== X-Google-Smtp-Source: AGHT+IFR7/NpvPbd92DhuXWQ65taHBGQHzopKqApe+mFvJO9mzw/h8Jl6fUAhWF6dq4HqW9qTr9y X-Received: by 2002:a17:906:f94a:b0:a6c:7215:a195 with SMTP id a640c23a62f3a-a6c7215a46dmr227660966b.22.1717668686523; Thu, 06 Jun 2024 03:11:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717668686; cv=pass; d=google.com; s=arc-20160816; b=nPyXsHYsEE1T5g4PEIppn9PR6SWce/xec13ouah7wA2+hbD1mqrV0WaPTuiMY43x3q 1Bh+w/KTlTKrqC0ihpGoGKT0AEViWZtZ+kIo08RrIIneDf1AJ6p5vUmEItTEaUt44BP8 zn1h4IcIlE8Gdkw4pt4MjN/uj4XfigBYDi/JLSMTDi0tuY/dqQ/3bLESBWWWmYBy1pud rLcU0f7oaYhrRIje19sIthRg4wbis81gSIPCUNwfDlORA9k0zmcKX9MwNj4I2KOJT2jX WR1JkX5nKoEm98KdMoXc9jmEN/SopyaWOb6BGV0DpVUnFs0lYmo4jB+vyJQcCE1EoVPs J5cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aSSVkWNzaMpCFwtFKNictH+j9mKED2uTD+OcWRnyLEc=; fh=YUtbW9vXo4ZQdGoFv8JfcRaMDP+dQFUihtBPMVWiRT4=; b=sCQup7hqMp7gBeQmZfPyDqvdy2OV7r8RA17x7+daMAVoV0BOTiPG7NjZT/f5iH1Pro HbexlJ480M4L0yby52x1tHPTkt/ut9eJ3eDPQ7I9wuQ6TxEkQJt2OSm1j6yI+IgBQpq1 sRXyirS6J4sImopiwoyfMm0s3AX87G3x6Zw2uC7mGOMGXWmWXsMiv4xuVHSDymi/CNHQ KUBvbHfAuraMESrfSJHaTgmcQF4VIoG16nE4Dk5A91Pzq4Qrfs8qPEO2yQAXYLALh0Uu bRinrEv+mLKVwqdI5BEo5uYk9lMxZRRxIgVFmhoV0YitLHetfkOlVGwi0ff1OdQWNVxw vW1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2q20lej; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-204085-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204085-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c8074c0bbsi51381466b.1054.2024.06.06.03.11.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 03:11:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204085-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2q20lej; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-204085-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204085-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 196561F2541A for ; Thu, 6 Jun 2024 10:11:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94711190683; Thu, 6 Jun 2024 10:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="D2q20lej" Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 C265C190050 for ; Thu, 6 Jun 2024 10:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717668667; cv=none; b=lAgvZ7vh7bvv4nXL50dZioKvQBNO1qJwJFR7fTbOqMQFsWDnadL+Ujwv+yXESdx9ieiaHvIguEhzLdZsk1nGG+0gxhncIL9WpVcKojEjOe21g6nwSSeokPSy/K1ubxMvsn5SIBahEuAQnIcMZLsdrqvpDChhFIe+596C9jFUVgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717668667; c=relaxed/simple; bh=b7Zwm8tYyK4TmWiUeSfOZCpOhR0FISw4INShYVYJW7I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bfvua+xpJlInGyt3YCVTjA7m3fZSNKo09Sob5+fpJCA/nv83YsYeyt8I+xoMcvJduq8UtWk8L8sNxUy/DglFxRxjC+iBPrqj0wsNjm8bI8rQ+nufpl4UkMEL+KS2WBNTI+x0KGqSMMtTD0LHPRY+iCZvCY47uOCxjeeCWt68DoA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=D2q20lej; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-57a2ed9af7dso1082451a12.1 for ; Thu, 06 Jun 2024 03:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717668664; x=1718273464; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=aSSVkWNzaMpCFwtFKNictH+j9mKED2uTD+OcWRnyLEc=; b=D2q20lej//O4Ig5uQBbj9vAnyH0T1qieMUsxo6PmrX64iwhnr0TxxAl1NcBfCT24rZ A67yuBK8wJTcqRNkVpbzgegQtcsvhntr3Vqv1dwUskU+8wyp3AqL1kjy3MI80NEu6Aw7 u4l8F/nNctlaZGkxTPkHOmttdevvYP04dEZ59bOXzjVQoOEuyzucY+gEm0KbVXq7zv0/ Tc3PQHAFfyK84O7HixMMsImZuzFQ4jgRV3lqsxjxnZ0JeZr2MeEn+1SM2CKAW5FopqAV /BqNkrxPLNZAVPt9BmZi4HRB5HIEKXlWm4g6YP0jIDqLSM/cGaczjuZsf+W3PAr2JaQ/ 4EmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717668664; x=1718273464; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aSSVkWNzaMpCFwtFKNictH+j9mKED2uTD+OcWRnyLEc=; b=K1tzJxqxTP1THYLU219aXUa6uQzy/aaqFSHUghIRxSsUrO7vjB4i2w+VuE0ihVnxUK BpCsB/KugXAcEi+sx7lSqgpDU9lZr89xROoQ4hs4gPYj+kmm/NZqdElfVUgRyEcSPzQw bITEw71I+HvjRwqdD5B9wOhjplYMvHVvVs65Vuv63TmApVJMJkQXSkSkwQJHWfJhCZkV J4IrgZeFZ4iTbd3Yy/aZH+gwyjOskY7ZkHNyyhtm5pCsK6l4u4qUj3eEDFJR9s6uCA19 ZtJ76dJELtvKjZs8qgsyeUthIKW+XhYocTz0UUekHD5mPF1nMAMbctNuoK7WH57geMvG HcKg== X-Forwarded-Encrypted: i=1; AJvYcCWMLUv2BMEjdYlYragY4oQ4rG1YKstt6YFNWjzPAoXziUF0VamsVTBbIbiWepsQOM+3FLty++ch+s3ioLO73zMFQkO6iWKQ6O7PA+85 X-Gm-Message-State: AOJu0YyU2qatbp+i/+CAhe0G+tMj76zBc6v+fGAntLz6TN9kmpSG53l6 +l637wQvXPHo+5hr8j6WhRxzrN/xaU5PFmBmBTVPR51IF9Cw1stGdetAdwIvbWQ= X-Received: by 2002:a17:906:3544:b0:a6c:71d2:3311 with SMTP id a640c23a62f3a-a6c71d23352mr224386166b.65.1717668664006; Thu, 06 Jun 2024 03:11:04 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6c84aa8351sm49462166b.142.2024.06.06.03.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 03:11:03 -0700 (PDT) Date: Thu, 6 Jun 2024 13:10:58 +0300 From: Dan Carpenter To: Joy Chakraborty Cc: Greg Kroah-Hartman , Srinivas Kandagatla , AngeloGioacchino Del Regno , Lars-Peter Clausen , Sakari Ailus , Bingbu Cao , Zhihao Cheng , Jerome Brunet , Martin Blumenstingl , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-media@vger.kernel.org, linux-i2c@vger.kernel.org, linux-gpio@vger.kernel.org, linux-mtd@lists.infradead.org, linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, manugautam@google.com Subject: Re: [PATCH v1 07/17] misc: eeprom: at25: Change nvmem reg_read/write return type Message-ID: <2b979aa4-3a63-4010-9670-294ce7624e18@moroto.mountain> References: <20240605175953.2613260-1-joychakr@google.com> <20240605175953.2613260-8-joychakr@google.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=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 06, 2024 at 03:12:03PM +0530, Joy Chakraborty wrote: > > These functions are used internally and exported to the user through > > sysfs via bin_attr_nvmem_read/write(). For internal users partial reads > > should be treated as failure. What are we supposed to do with a partial > > read? I don't think anyone has asked for partial reads to be supported > > from sysfs either except Greg was wondering about it while reading the > > code. > > > > Currently, a lot of drivers return -EINVAL for partial read/writes but > > some return success. It is a bit messy. But this patchset doesn't > > really improve anything. In at24_read() we check if it's going to be a > > partial read and return -EINVAL. Below we report a partial read as a > > full read. It's just a more complicated way of doing exactly what we > > were doing before. > > Currently what drivers return is up to their interpretation of int > return type, there are a few drivers which also return the number of > bytes written/read already like > drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_otpe2p.c . Returning non-zero is a bug. It won't break bin_attr_nvmem_read/write() but it will break other places like nvmem_access_with_keepouts(), __nvmem_cell_read() and nvmem_cell_prepare_write_buffer() where all non-zero returns from nvmem_reg_read() are treated as an error. > The objective of the patch was to handle partial reads and errors at > the nvmem core and instead of leaving it up to each nvmem provider by > providing a better return value to nvmem providers. > > Regarding drivers/misc/eeprom/at25.c which you pointed below, that is > a problem in my code change. I missed that count was modified later on > and should initialize bytes_written to the new value of count, will > fix that when I come up with the new patch. > > I agree that it does not improve anything for a lot of nvmem providers > for example the ones which call into other reg_map_read/write apis > which do not return the number of bytes read/written but it does help > us do better error handling at the nvmem core layer for nvmem > providers who can return the valid number of bytes read/written. If we're going to support partial writes, then it needs to be done all the way. We need to audit functions like at24_read() and remove the -EINVAL lines. 440 if (off + count > at24->byte_len) 441 return -EINVAL; It should be: if (off + count > at24->byte_len) count = at24->byte_len - off; Some drivers handle writing zero bytes as -EINVAL and some return 0. Those changes could be done before we change the API. You updated nvmem_access_with_keepouts() to handle negative returns but not zero returns so it could lead to a forever loop. regards, dan carpenter