Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp281511lqt; Thu, 6 Jun 2024 03:32:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWhcvYa1MR9TMI5TJ5UPQzs6qkUJU3XELZgEf4UIUjPm26vtdqHbWa/BwkBNwzGZH4hdhrsGnb2f9I0OQulqcUKhAENGO9dz+MliXxzkQ== X-Google-Smtp-Source: AGHT+IFwIqHZCIy2VC+TaYKSr+esb3QHhdpiKZid8fP8wRLJyJig9lUYFhPBnaQUymK0d9lL3jGM X-Received: by 2002:a67:fdd6:0:b0:48a:647e:b804 with SMTP id ada2fe7eead31-48c047cb7dcmr5284158137.1.1717669946063; Thu, 06 Jun 2024 03:32:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717669946; cv=pass; d=google.com; s=arc-20160816; b=rQnpco+jDUFs430SfodDntqE/drWhmZIKUNpxx4ApAIL8pY6iXtJeowgNEyYQFSvGK V9b1DK7c1oYimXoqbjoYp9SaT3gCfe2FfxRelxng6qJYHZViCR/EUMkESdJ67AdT+4cA tm9rQgOlQIXYdV/T85NSTFuUb//PedhrAyyj3B9djytIreinzgED1KlWRt+FoFBgJN0E n948b3yGL9xFKkDBB5KnvTxEPlaNDsU3OY725KkzGQZkH3D3EK1wq6YkVBFYd+oVj7bw eoO7Z3C8n868VCbn0lQlwQzPBRvcbA6G7OoJe9QRBXOm1/u8s4NRsaIJL8g5zPoTc2v7 47+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=2yOK4FlQCW+JMOCwnWP72jJymCtr5dD6IgIpna60BCY=; fh=Y/MG/RjlHLfVKj4TCZw3xj/HRtALhm+j6nwEyjF0kBg=; b=mkHNHl3Sl7qpifBxhMM9tloPSxYoXepJ/Eaeo8jXmmCIoVbPnLBnx6fZwdXbgisLP7 NU3aYBsWwi8vxm8UAUjSywyZGtXxmjpmfo536HbakUygWqUjoIFmyC9M761wyXBwC9zM Re/XowLDLFTubkzoG6FbyUZ6ey6OqbA1EkejgqnSp/ctq5o0VdTeSDbetNAi6N/gp9Ay EgRK+KYCtQVBL0TfH6Vq2M2/XOS11t84IDi10RJGc+m4eJ6I/PTlblMCozS+JxdOgjag EsYqRhe11XAjx85+9VOeJrz91sGTAIQZ6yn3pFNx9cOrZzX/TnGvcKKetNbALksoCJ/R KBFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Ij9/iU/U"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204112-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204112-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-795333390eesi108430985a.557.2024.06.06.03.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 03:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204112-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Ij9/iU/U"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204112-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204112-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B26B01C246D5 for ; Thu, 6 Jun 2024 10:32:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA92E1922C3; Thu, 6 Jun 2024 10:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ij9/iU/U" Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 0F1CB194C61 for ; Thu, 6 Jun 2024 10:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669926; cv=none; b=ReZK6h41T+Zur31zFwjnFFYgo73mNJfBD7RA7GaLLvhV/HOYKAGyXJ8b14gDc5KSz4RBvg2HGt3iYbHf/AUa/q3ughZ5jMTXb3doAN83k+7ZNNcuI+8xq6RlkLVUSfniBHd7TldgRnKWYDO9PJWj3QsOWd9lOyTxT7FODZ+Dhrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669926; c=relaxed/simple; bh=n0hrzdYnBksW+DamHG6BupTO1J0YAJybs/VDL2sugrE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=uov7lggP/0YGwIvBHiIfFjDEWi42ZJFL98ws2FeWrQZ3w3tfNv89+MeZOz3y9h2K5LMhzXe3UrgwGo9wiXVadHDl+1YmIbSMA8nRwc6R15o7kz8dzcLMPoMAPrsH1h/yDpT8p7tjgeou0RIeXelIBRWV/jnEf0iLIAfAbOSPVns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ij9/iU/U; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2eaad2c673fso10432281fa.3 for ; Thu, 06 Jun 2024 03:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717669923; x=1718274723; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2yOK4FlQCW+JMOCwnWP72jJymCtr5dD6IgIpna60BCY=; b=Ij9/iU/Uyo6fcf8LONJ7xC09lvYBG8qaaeEz4vBXq2BTPZbQ2/pF3yyQBM4fRbFGfh G2YVI79pdecNzRewdbn8sACLDUSzd7rOjlh6zMMORYPcVD1QveoeZ2kHNSsE+9FRNNbv STcLcfiwZHhGsSEvRFW5mX9h4B8YphLBoSkl78uJsHCRnl9eDwrE59GFqtGknBB9mMy1 OSPuYgWTVQS8j2w3KVuq+5S7UftcTUbs1qQVWVzbjEhqRqb3+fKICTURvn7oWD734yHM ft1saZpU5WP1Di0/lkFYY358dTnV3FFIlPJYisX1EUMUoYuw+wFXKiytWhGLxoNHAlTO IcBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717669923; x=1718274723; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2yOK4FlQCW+JMOCwnWP72jJymCtr5dD6IgIpna60BCY=; b=NpWxCR4WmV3TpjTam7fdAjQNQtja5IwZsk+V95ia+klBGjUoh8ajK3LiIDl9sAEjfr FpWyf3UJAQa02/Ia2aG/FNZnOcGTmzdAK1KBampW8ZesvngFped5YSp+YMsfPsBEbWOn fyiKbP43wpCx+80VxyAxcbTYGJIBOzSrxIkikf5bWYyCEs/jNNlDXch4KlBTcMwuAeDk ykWCe/p+gVgqwc6OPfY8kd5ifJh2epxKF1gaIwpTZuv4yYhGDD7w0b0blyYGBCdDagXZ b7kboQxHAfgZR/RvtZ5AUZBI36fLw/gOBlsIwcAcsQevh/gx23z+F0KFiRXaIHAdN+Ub c0Eg== X-Forwarded-Encrypted: i=1; AJvYcCUAxkIxY6xmQLmZ065+lzjtVmRd4bWcppEHjYJi7j85uwi9nsn9ALnu4W1hs4JjbgXqghouEJBw/OCjND0L2+jv1E9GlU/wsAlvuoF4 X-Gm-Message-State: AOJu0Yy3st/Xe9WvMg+QTE9m9ixie11JHOIBpcgezAvQ61VxwoXHpJ2i 4D1Y8gGHhwP7MXfs+YMaiAERRNR4lo2KnVi2qj5XwnekyzGM4H7ltvelHJvqFErkob1dcCRtjqv /GKX7IPoD0zEaxu4l09e4bdkIvR+aPRBsCAHP X-Received: by 2002:a2e:9643:0:b0:2e1:9c57:195a with SMTP id 38308e7fff4ca-2eac7a5fd4dmr33302121fa.32.1717669922881; Thu, 06 Jun 2024 03:32:02 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240605175953.2613260-1-joychakr@google.com> <20240605175953.2613260-8-joychakr@google.com> <2b979aa4-3a63-4010-9670-294ce7624e18@moroto.mountain> In-Reply-To: <2b979aa4-3a63-4010-9670-294ce7624e18@moroto.mountain> From: Joy Chakraborty Date: Thu, 6 Jun 2024 16:01:42 +0530 Message-ID: Subject: Re: [PATCH v1 07/17] misc: eeprom: at25: Change nvmem reg_read/write return type To: Dan Carpenter 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 6, 2024 at 3:41=E2=80=AFPM Dan Carpenter wrote: > > 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 re= ads > > > should be treated as failure. What are we supposed to do with a part= ial > > > read? I don't think anyone has asked for partial reads to be support= ed > > > from sysfs either except Greg was wondering about it while reading th= e > > > code. > > > > > > Currently, a lot of drivers return -EINVAL for partial read/writes bu= t > > > 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. > Yes, I will resend the patch to fix that. > > 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 =3D 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. > Sure, we can do it in a phased manner like you suggested in another reply by creating new pointers and slowly moving each driver to the new pointer and then deprecating the old one. > You updated nvmem_access_with_keepouts() to handle negative returns but > not zero returns so it could lead to a forever loop. > Yes, that is a possible case. Will rework it. > regards, > dan carpenter > Thanks Joy