Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1586122ybm; Tue, 21 May 2019 17:09:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy632go0yqOZRVRTSngo9ttQ+dg5H6NWYXWgzynwbUQ8/DHksCai7VqSVFaeRQO5JMuq2E+ X-Received: by 2002:aa7:864e:: with SMTP id a14mr81181339pfo.132.1558483798837; Tue, 21 May 2019 17:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558483798; cv=none; d=google.com; s=arc-20160816; b=arzRgAGgtHYabbeJ3C85qhCTKzVdvlbOVSyjLtGu6Sae0MkcPsuVNjb0tbgiQWatti iTE6b1MAb0pmQDQFNl9kBn3+yLQePZiRU8yE7u0D3ixmW8cq4z9fwKEIw+O4nMIj/Iv3 YsZ9NSM+BBMrBSGVg+wNq3ireHffYwWSVPZUrpYkX7uGLhjuv6TzQ+sT2e/seG0P4qNX omHhO8t3pyPbSNSSOOs2QNIKmsv2oKB1IFBFj8NTLGXReLMuyJ+cWVHpRpujC/nGjnwh Ga0TIVZBxvbjVy/P5xjtRGGleWp9FT/KyKrjsFLrH8MjaoMSI6bEmhQIwQjtDrLE/Yv1 sVBg== 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=4vBMADYmnJSt2XlDMdbmk4Hf0OrCwBXEHiQQvrZH6HM=; b=N9eohBNyhq47ilaH48w21Qk1n1YZp2FGNKa0VmZ6/yuukZnLYAXEf4fm+eynK4tU+f YM/DVo0TrqT6Imc3qGvcX9GHzMbNo48ImkjAH2KwHVvPYWJIc7pm9fAlAO7IBFqfNONr s1zpt1iHgoEgKiW50E61BwDKlNhgUiFhwol9FMSWqMScRP81BQJBBbKexiWPrJYT3KpS ihUIXV4CmBguBo4/n+NfSc5b1jbi1ow/wlpVa/1CGSw2JwUanH/cAfrEiW2Uzzufai4A RbOMP0NSXwLaqjF87xa4ylTvg67lY02iijSyFDjyFqORug1mZsgjnE7NBK8WYWNoJ6gi xWJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=svj6280m; 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 n6si22171064plk.237.2019.05.21.17.09.42; Tue, 21 May 2019 17:09:58 -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=svj6280m; 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 S1728042AbfEVAH7 (ORCPT + 99 others); Tue, 21 May 2019 20:07:59 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:37148 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbfEVAH6 (ORCPT ); Tue, 21 May 2019 20:07:58 -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 38C8C891A9; Wed, 22 May 2019 12:07:56 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1558483676; bh=4vBMADYmnJSt2XlDMdbmk4Hf0OrCwBXEHiQQvrZH6HM=; h=From:To:Cc:Subject:Date; b=svj6280mLrmcPUSBHSGiN8f6seclFeA+xN6F74OrwbVPfOoDTnbMznq3Z6R8wYOtX 45zn1y5GHvXrdOcS1tLPOTVNC/j4Lke3YMR6rI3RFomy6LjSssuKZJ1yDb4jLqZUYD 1JsugsEVlPk2APR5lcJx10ms/5lz0ftAnqHFAx6+nSmTnaEpZQAHdoYiPEWykdrZJ+ JyZjdIQXdqF5N0V0Q6dRNwrsct2GpcjBr1jh6TGChD6lCmSxOatcWrFEzIg7wojShh rBUj/DVhlVv9sG7s/jYI3+VgwRFgpJ1StJ0TWWDPg1fZJHpfiVO2+LYwBF4Ekgt7as CU6SEUWq+JvQA== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Wed, 22 May 2019 12:07:55 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id 11E2013ED45; Wed, 22 May 2019 12:07:56 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 6B6781E1DDA; Wed, 22 May 2019 12:07:55 +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 1/2] mtd: concat: refactor concat_lock/concat_unlock Date: Wed, 22 May 2019 12:07:52 +1200 Message-Id: <20190522000753.13300-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 mtd_lock or mtd_unlock as an argument. Signed-off-by: Chris Packham --- drivers/mtd/mtdconcat.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index cbc5925e6440..9514cd2db63c 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 le= n, + int (*mtd_op)(struct mtd_info *mtd, loff_t ofs, uint64_t len)) { struct mtd_concat *concat =3D CONCAT(mtd); int i, err =3D -EINVAL; @@ -470,7 +471,7 @@ static int concat_lock(struct mtd_info *mtd, loff_t o= fs, uint64_t len) else size =3D len; =20 - err =3D mtd_lock(subdev, ofs, size); + err =3D mtd_op(subdev, ofs, size); if (err) break; =20 @@ -485,38 +486,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, mtd_lock); +} =20 - return err; +static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + return __concat_xxlock(mtd, ofs, len, mtd_unlock); } =20 static void concat_sync(struct mtd_info *mtd) --=20 2.21.0