Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp898180ybm; Wed, 22 May 2019 13:31:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNjY7kJaba+JePs1Ko1Y4FtES8bt/r7ka/ey96+5fBCBZOJHLT6q+csjCa9XD1pHDMbcKP X-Received: by 2002:a17:902:d70c:: with SMTP id w12mr44138971ply.95.1558557104916; Wed, 22 May 2019 13:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558557104; cv=none; d=google.com; s=arc-20160816; b=EbLTkR9lt90/e0S83h7LNnnPu30XWHTPH3JIVHqOwgWprf4fADgR3nKfcGe+HAsbnv LG3e+D81twlrzweOA0kdo4adVF7jvBuXr5TSfQoxmCVybN1Xjg1AjGbTXplXHRIXALlB d7UtyoOKE7VO7u3LmwjgpkvDTPNBnNY+vG8214bJMLwXoCoVEo02gFDDBb5PZysnYqmA sF4VWQZ10KQREP85HpBQVArKcGU/o5LEWIz4VMXZR/tZ3jMVSfJW0U1KseYGzUwRSIZY MxvAK+MkgFoA4SAReYTZLKOXse3k/K0ZEffJQ1EkdeiVGbu/dNjLPHRV89xTHoFahViz gPqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sC3y19sKHEp/s8yyLY2YBtsOBxNiD5rQEEH0tqDB6yI=; b=GoayhpoGa2iNRGd1bpbSsoHq/0ffRrEByYu4f62BHjwKA+9/bmvYlUJ2hvn2HNO/YT C3vZHeqahi/WP2ny7JKFrRVgXDBDL1xObRjXHqmp8197tCLALCXtszlzPEA8lu7mpFiL 184RxZaQFzNMqi0zvA9J+pGt9jOac+xNPVfcld90DFmBEBJotTnclo2Rwo6XjavsGMV6 gu2ZqCcCbHyFhMW89co9L/xfb4tdLkwN4hBUqi3Kslx5vMtAPpZAxF5CVCfgN8Ehnc/c PvxGTrNmDbmxZ+NdjoZ4F+we0BkwV24ILyB4lRQvA+pyjIW/I4EzTK2yTX3gg3o4Wl8K ieUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G2c9pLon; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si29340914pfc.89.2019.05.22.13.31.28; Wed, 22 May 2019 13:31:44 -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=@gmail.com header.s=20161025 header.b=G2c9pLon; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729940AbfEVUaV (ORCPT + 99 others); Wed, 22 May 2019 16:30:21 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35762 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfEVUaV (ORCPT ); Wed, 22 May 2019 16:30:21 -0400 Received: by mail-wm1-f66.google.com with SMTP id q15so3546055wmj.0 for ; Wed, 22 May 2019 13:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sC3y19sKHEp/s8yyLY2YBtsOBxNiD5rQEEH0tqDB6yI=; b=G2c9pLon27AIci+0l2Y7s2L5FjbKg/u155sKOM/AN4igPsIl9bFZu3YqzEmBLe2VSN jHsDIKHucWAF/zth90hQq32UkNdkYA7ed9UEGoIrR/CIcXp+iFZnHkHPV4UM5Volvnqi 46Nze78L1H+qEAfI+Dz/5o87tLIHVm0zg2YAsHIBczNqDfBq4T3yL41T4+7uiVUdGlbY IUFK1J0gdszsfaTDCNd/5oPee21k+bEgfJuEpcZPpFXWXgAMm3UU+F8PjFw54wbtIHIn rSmEnD+X8P8LJqpgCA8pDtcUh9qnbJiqDAPYWk5HcW9ypjDRLDybNDJY925eksQ5myGF UoTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sC3y19sKHEp/s8yyLY2YBtsOBxNiD5rQEEH0tqDB6yI=; b=METrEAZTcOTm00gAQaA55Oo+HNsrgc+GGzgI1yRXnEG08AQ4aIJdAiqlDb0bPG2Z/Z rePdtWkQiXm3X+T0RUeDDswfyCrLaFIAcMBUhLn9gsDcjfMhRK1FSNlGQheZEAPN+Y11 49fpRDQGpJ06OuF7AMNBrFVGTyhZ/dlIOkoaL1aR//0C/jzyFlg8df1qw0x1xp2SnMWc 3C8JUgIeuB36ffTLGleQU4a95DFszb/CCIaX++Ww/wU/+fRWEBE9hl269h0M0PboShn8 32gTIn52HLyQBwkn+MSePmsaMGUGZ0rXtzS6CgTyuI9+VUPaxwLxLczkTZFe/+4n63Kw dXRA== X-Gm-Message-State: APjAAAX8boxKoIwWaFtwpBEDfYA5km8qqzt5M2G4GY0J3XBTZEjPElNv FsmrShgj9tZkoAfPlMGglLOIunBv/uUzlPKBXg0= X-Received: by 2002:a1c:4087:: with SMTP id n129mr9133575wma.14.1558557019332; Wed, 22 May 2019 13:30:19 -0700 (PDT) MIME-Version: 1.0 References: <20190522000753.13300-1-chris.packham@alliedtelesis.co.nz> In-Reply-To: <20190522000753.13300-1-chris.packham@alliedtelesis.co.nz> From: Richard Weinberger Date: Wed, 22 May 2019 22:30:08 +0200 Message-ID: Subject: Re: [PATCH 1/2] mtd: concat: refactor concat_lock/concat_unlock To: Chris Packham Cc: David Woodhouse , Brian Norris , Marek Vasut , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 22, 2019 at 2:08 AM Chris Packham wrote: > > 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; > } > > -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, > + int (*mtd_op)(struct mtd_info *mtd, loff_t ofs, uint64_t len)) > { > struct mtd_concat *concat = CONCAT(mtd); > int i, err = -EINVAL; > @@ -470,7 +471,7 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) > else > size = len; > > - err = mtd_lock(subdev, ofs, size); > + err = mtd_op(subdev, ofs, size); > if (err) > break; > > @@ -485,38 +486,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) > return err; > } > > -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 = CONCAT(mtd); > - int i, err = 0; > - > - for (i = 0; i < concat->num_subdev; i++) { > - struct mtd_info *subdev = concat->subdev[i]; > - uint64_t size; > - > - if (ofs >= subdev->size) { > - size = 0; > - ofs -= subdev->size; > - continue; > - } > - if (ofs + len > subdev->size) > - size = subdev->size - ofs; > - else > - size = len; > - > - err = mtd_unlock(subdev, ofs, size); > - if (err) > - break; > - > - len -= size; > - if (len == 0) > - break; > - > - err = -EINVAL; > - ofs = 0; > - } > + return __concat_xxlock(mtd, ofs, len, mtd_lock); > +} > > - return err; > +static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) > +{ > + return __concat_xxlock(mtd, ofs, len, mtd_unlock); > } > > static void concat_sync(struct mtd_info *mtd) Not sure if it passing a function pointer is worth it. bool is_lock would also do it. But this is a matter of taste, I guess. :) Reviewed-by: Richard Weinberger -- Thanks, //richard