Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1041663ybm; Wed, 22 May 2019 16:21:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqypz0aKBBEobRnUgAQADfhIJrgIrXsmY0pzw1yt1sAA4UHR0Xr25miP++2Mgcnbvu2ZxN2+ X-Received: by 2002:a63:c64c:: with SMTP id x12mr92138788pgg.379.1558567277382; Wed, 22 May 2019 16:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558567277; cv=none; d=google.com; s=arc-20160816; b=ualCGNgrjUZvpnQRkvRQc82tsIVt11GioHtOgPBIFbf+8DWjHwmnPBW19pnK/hCGPk k5h/vwKleh18CWXIUr1Xnpf9bTWRqHgN9GTPNIYeOvpc3eJ3bNVeXPGLIef21/65DcrX PzBP7kI2/n9n8hK6MOCkhiERw+YryPhYNiEvNnC6r6KBGfLNhzUzfhojr/8cs/t3IKZ7 sXGKrLRHuy5v2DvFFV/xG3oZeCCgzgecrdMtr0nytq5VlMwu+9bRw+51NzxMpP86Qbc8 doLVJiq1u2shgtHvfW3Ihlsgzifl67RxmM6c/NRzmt/NoiUKHNQS2bxLWsAa7j1OPlql yAbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dtuLuNHN5PQXizzBuOQOvLynHSt8GJ82TtRR1qtMiT4=; b=I1zJMVk6wjfyqkI7HOfp0P0CudYgw7d1iCzGQ04iJ8m1s0U7P0ny2vf7RUSQPuNZ73 8AXndcFMUoRsZxlMOYIjOr/E2e5dTPRLEpJ3Jb55GbcyaTicmk0sUxrXyzaB6NS+DrWE UKlbkDwfQEjeuCj/nkdrWu/xq528K+WkzdXXca3R7yqcGqNRKOjThyw1PDYslituCJOA sbxxB9xodJ+4fNWvA6cKV0Qp4HDIm+i+TGyxau0NSRr8NchCa8hRcc6XQ0OOurxCB7Ax wsNmCW7lR7MH61aX0doftwXCTPD/x4yhrwJ6beOy+pXYBNuph1MTQuJSEnsXN2x0xuQE Uh6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=SpQUo2kH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alliedtelesis.co.nz Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r24si25316785pgo.573.2019.05.22.16.21.01; Wed, 22 May 2019 16:21:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=SpQUo2kH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alliedtelesis.co.nz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbfEVXTz (ORCPT + 99 others); Wed, 22 May 2019 19:19:55 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:38979 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726215AbfEVXTy (ORCPT ); Wed, 22 May 2019 19:19:54 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 24A96886BF; Thu, 23 May 2019 11:19:51 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1558567191; bh=dtuLuNHN5PQXizzBuOQOvLynHSt8GJ82TtRR1qtMiT4=; h=From:To:Cc:Subject:Date; b=SpQUo2kHmD9iW+Med7PaWO1niPYiux1juSNW5zZ+hmTaQegqk6dRKUW2/a2F6F/6R UCFcsFHG90w2vrERyM4A1Tl5dzIAjNyZmluapsp2A+ijCXkUd2orNVBWzBUxobvqOD PYqhcCWnJFmkbdcZ5X7Zd3Tl9e2A/RGvnw0XRl25gt/c7VB62DbiGklci2typO0AKJ ZEAP9j5n13dDd8ZbcqwRZt8S+rElczc89r7+wGeWhX7H5SMR7r6ZpRr6pZEQZonGMt CStO64/uSfoKsbcAJt5hutzpPxyFEAL0x50gFK2pNg3GmvoHcWixo+qXUPLjTnGi8t H2TGANI+Z2+0w== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Thu, 23 May 2019 11:19:48 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id 0EA9413EE11; Thu, 23 May 2019 11:19:51 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 601B51E1D5B; Thu, 23 May 2019 11:19:50 +1200 (NZST) From: Chris Packham To: dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Chris Packham Subject: [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Date: Thu, 23 May 2019 11:19:47 +1200 Message-Id: <20190522231948.17559-1-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable x-atlnz-ls: pat Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org concat_lock() and concat_unlock() only differed in terms of the mtd_xx operation they called. Refactor them to use a common helper function and pass a boolean flag to indicate whether lock or unlock is needed. Signed-off-by: Chris Packham --- Changes in v2: - Use a boolean flag instead of passing a function pointer. drivers/mtd/mtdconcat.c | 44 +++++++++++------------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index cbc5925e6440..6cb60dea509a 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -451,7 +451,8 @@ static int concat_erase(struct mtd_info *mtd, struct = erase_info *instr) return err; } =20 -static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +static int concat_xxlock(struct mtd_info *mtd, loff_t ofs, uint64_t len, + bool is_lock) { struct mtd_concat *concat =3D CONCAT(mtd); int i, err =3D -EINVAL; @@ -470,7 +471,10 @@ static int concat_lock(struct mtd_info *mtd, loff_t = ofs, uint64_t len) else size =3D len; =20 - err =3D mtd_lock(subdev, ofs, size); + if (is_lock) + err =3D mtd_lock(subdev, ofs, size); + else + err =3D mtd_unlock(subdev, ofs, size); if (err) break; =20 @@ -485,38 +489,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t= ofs, uint64_t len) return err; } =20 -static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { - struct mtd_concat *concat =3D CONCAT(mtd); - int i, err =3D 0; - - for (i =3D 0; i < concat->num_subdev; i++) { - struct mtd_info *subdev =3D concat->subdev[i]; - uint64_t size; - - if (ofs >=3D subdev->size) { - size =3D 0; - ofs -=3D subdev->size; - continue; - } - if (ofs + len > subdev->size) - size =3D subdev->size - ofs; - else - size =3D len; - - err =3D mtd_unlock(subdev, ofs, size); - if (err) - break; - - len -=3D size; - if (len =3D=3D 0) - break; - - err =3D -EINVAL; - ofs =3D 0; - } + return concat_xxlock(mtd, ofs, len, true); +} =20 - return err; +static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + return concat_xxlock(mtd, ofs, len, false); } =20 static void concat_sync(struct mtd_info *mtd) --=20 2.21.0