From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BEB2C6FD1D for ; Mon, 20 Mar 2023 07:57:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B94685A62; Mon, 20 Mar 2023 08:57:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BoPRQTu+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8095E85A83; Mon, 20 Mar 2023 08:57:21 +0100 (CET) Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A69F88450D for ; Mon, 20 Mar 2023 08:57:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pg1-x530.google.com with SMTP id d22so6083727pgw.2 for ; Mon, 20 Mar 2023 00:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679299036; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=saqF/qlWM84HmesBbuA2n44Riq9kKQEqIH1hjYg2HB4=; b=BoPRQTu+i5qBaKi4hj0WLhpmYv+BztY+PmxkkeVxSUaXkyXCvsQa51M1aBiu8WgCdQ jEd1SvUJbt76TYCK85qwPg5mpY58t417BdDyqurQbCtIcDU/DXhMD66eXc3VYN8zs0U4 UiU5bHCy6pppJL/D9BouCvBFTBSpXwSsZF6zmBXdjwZ336Zl7Pw0+Snnua+Vnw/WU6ae I3CvRIw0AIH5SRbJVlqdZANlLmclhQCVPKW6C6+0Aoz+bb0cQ3S4Mls8ixc087ectCdJ /k5AqMUsEFofbxuIZ+8VqKciy7QiGDULyy2q5ssTVSObFjzLJnN5tGZO36ILYKFib984 GXoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679299036; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=saqF/qlWM84HmesBbuA2n44Riq9kKQEqIH1hjYg2HB4=; b=cAqcV/pV9CtM9rvU6CvT+lWDteKHiUso7BVrnqq94jgMvIFe/X6XYrHZI/dSzht0mZ IExb/dIeqZxPJFjfNhoOLZyleedyaZCUmShfDWsLRNw+EFyiMLwWbEo8E6IwavVb7RfM TKYXoc8r2lWgB9/Y7QQfeVNECsIL+M9iDgzDhzHsmRZayZaQc4LfJotxfR5rPKLHWQsf 0YSNzlJVS1KG0OLSlhS1UCjv0fKZcQGr4hgDo0k+LTLaled5+ufQ50iBGZziJpIdawB3 U3JxQ9CT7A99SGLcm9vsOljrXVRBmzQOkb78lz45PPxw+MxT70KHY4at3gDB6kYO7O1o 5aHA== X-Gm-Message-State: AO0yUKWjH8m1MQA68j5kUk7h0h/5sBh2qQvMuBnqLrgpbiH6l6VW8Z6Z uFj0x6ksyTuiEeHvISvycfSV0g== X-Google-Smtp-Source: AK7set93f7YhJ/qMuhg7KAAF4yePTppvvan0yFgb3mZ2Itch856O9mCl5Kndzf9dm+wH5AY27RUdbA== X-Received: by 2002:a05:6a00:418c:b0:624:bf7e:9d8c with SMTP id ca12-20020a056a00418c00b00624bf7e9d8cmr15931665pfb.1.1679299035764; Mon, 20 Mar 2023 00:57:15 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:2b9f:dd1a:cfe4:a9d4]) by smtp.gmail.com with ESMTPSA id j13-20020aa78dcd000000b0062809b2cb05sm148100pfr.155.2023.03.20.00.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 00:57:15 -0700 (PDT) Date: Mon, 20 Mar 2023 16:57:12 +0900 From: AKASHI Takahiro To: Ilias Apalodimas Cc: Simon Glass , U-Boot Mailing List , Heinrich Schuchardt Subject: Re: [PATCH v2] disk: Use a helper function to reduce duplication Message-ID: <20230320075712.GA48637@laputa> Mail-Followup-To: AKASHI Takahiro , Ilias Apalodimas , Simon Glass , U-Boot Mailing List , Heinrich Schuchardt References: <20230319192957.1084530-1-sjg@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On Mon, Mar 20, 2023 at 09:31:58AM +0200, Ilias Apalodimas wrote: > Hi Simon, > > Patch looks good, but isn't the new function name a bit misleading? > Something like blk_part_find_start() sounds a bit more descriptive, or am I > missing something? I don't think that the helper function works as my original code does. > Cheers > /Ilias > > On Mon, Mar 20, 2023 at 08:29:57AM +1300, Simon Glass wrote: > > Reduce the duplicated code slightly by using a helper function to handle > > the common code. > > > > This reduces the code size very slightly. > > > > Signed-off-by: Simon Glass > > --- > > > > Changes in v2: > > - Rebase to -next > > > > disk/disk-uclass.c | 46 +++++++++++++++++++++++++--------------------- > > 1 file changed, 25 insertions(+), 21 deletions(-) > > > > diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c > > index d32747e2242d..7f1fd80b2248 100644 > > --- a/disk/disk-uclass.c > > +++ b/disk/disk-uclass.c > > @@ -65,26 +65,38 @@ int part_create_block_devices(struct udevice *blk_dev) > > return 0; > > } > > > > +static int blk_part_setup(struct udevice *dev, lbaint_t *startp, > > + lbaint_t blkcnt) > > +{ > > + struct disk_part *part; > > + > > + part = dev_get_uclass_plat(dev); > > + if (*startp >= part->gpt_part_info.size) > > + return -E2BIG; > > + > > + if (*startp + blkcnt > part->gpt_part_info.size) > > + blkcnt = part->gpt_part_info.size - *startp; > > + *startp += part->gpt_part_info.start; > > + > > + return 0; > > +} > > + > > static ulong part_blk_read(struct udevice *dev, lbaint_t start, > > lbaint_t blkcnt, void *buffer) > > { > > struct udevice *parent; > > - struct disk_part *part; > > const struct blk_ops *ops; > > + int ret; > > > > parent = dev_get_parent(dev); > > ops = blk_get_ops(parent); > > if (!ops->read) > > return -ENOSYS; > > > > - part = dev_get_uclass_plat(dev); > > - if (start >= part->gpt_part_info.size) > > + ret = blk_part_setup(dev, &start, blkcnt); > > + if (ret) > > return 0; > > > > - if ((start + blkcnt) > part->gpt_part_info.size) > > - blkcnt = part->gpt_part_info.size - start; > > - start += part->gpt_part_info.start; > > - We cannot read out more blocks than the size of the partition. > > return ops->read(parent, start, blkcnt, buffer); So blkcnt must also be adjusted, otherwise we may see extra blocks beyond the partition boundary. -Takahiro Akashi > > } > > > > @@ -92,22 +104,18 @@ static ulong part_blk_write(struct udevice *dev, lbaint_t start, > > lbaint_t blkcnt, const void *buffer) > > { > > struct udevice *parent; > > - struct disk_part *part; > > const struct blk_ops *ops; > > + int ret; > > > > parent = dev_get_parent(dev); > > ops = blk_get_ops(parent); > > if (!ops->write) > > return -ENOSYS; > > > > - part = dev_get_uclass_plat(dev); > > - if (start >= part->gpt_part_info.size) > > + ret = blk_part_setup(dev, &start, blkcnt); > > + if (ret) > > return 0; > > > > - if ((start + blkcnt) > part->gpt_part_info.size) > > - blkcnt = part->gpt_part_info.size - start; > > - start += part->gpt_part_info.start; > > - > > return ops->write(parent, start, blkcnt, buffer); > > } > > > > @@ -115,22 +123,18 @@ static ulong part_blk_erase(struct udevice *dev, lbaint_t start, > > lbaint_t blkcnt) > > { > > struct udevice *parent; > > - struct disk_part *part; > > const struct blk_ops *ops; > > + int ret; > > > > parent = dev_get_parent(dev); > > ops = blk_get_ops(parent); > > if (!ops->erase) > > return -ENOSYS; > > > > - part = dev_get_uclass_plat(dev); > > - if (start >= part->gpt_part_info.size) > > + ret = blk_part_setup(dev, &start, blkcnt); > > + if (ret) > > return 0; > > > > - if ((start + blkcnt) > part->gpt_part_info.size) > > - blkcnt = part->gpt_part_info.size - start; > > - start += part->gpt_part_info.start; > > - > > return ops->erase(parent, start, blkcnt); > > } > > > > -- > > 2.40.0.rc1.284.g88254d51c5-goog > >