Received: by 10.213.65.68 with SMTP id h4csp2118707imn; Sun, 8 Apr 2018 20:10:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49tvwQSR55zNRZ7gCEKZXoy8VvGvyRUlOEN0KV7rgXgxeEPXCqrPtu9sFAD8z4vVJEgr3uw X-Received: by 2002:a17:902:20ca:: with SMTP id v10-v6mr37720126plg.9.1523243408801; Sun, 08 Apr 2018 20:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243408; cv=none; d=google.com; s=arc-20160816; b=dpc91hcp9+GmecQ3R23sppU6mSmo3APcr9wtcrW55aoY5tN7sP8Vm6YjkbzZx3F4aW U96qjSUIdVtSQiqyFFBTq7G42GBSyYiNfFSFTd9Z6esIwNl54UxvuMlj35wWraHhCIT9 bHx2iUlQa8uY4DRl5s06TAdGomY4xNesGKXhKP9i249USUmB6hRUujq0z2PU1+5ImfvT MZ64fv3e0oCgOabzdBd1oLwZKN5cyiLUUJuohpNakuRnQB11KmSAM2vrT77yg8M6VZRP mawvl2J0B5k/SF8n3KZUm0EpLZaLmlTIsXbrNNKm0vn/AUbMO6GU7WKL/JdqW4CZLv0t WPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=2Ddgc3wv0BgA+4wZmJ///QfhkNnPL1cDaS0l1tmnLjc=; b=rKqO682Xig+oPb00BAYcUHt/kxweCwpSgQ0/ZVKg5uEuAc1kmTWCxfz5xgtKTulSYx TtKc2zYAzsVGpXCBSMjaoh6pX/WNxjfHT+UbfH8d1mFraqgjMJ9PxTv4PrhsWEJjUTXZ bqUkY9WcsXikVyuI1HC2Rv5QEdQYP3jlhyWtq8VTMg98YYM+P5uDfdl0OHk0GC7YSHUQ S6SZjr9WFJgZgipLcdGtvcd4akWRU4hBSxrXWE7i/wuuZhr4NchC8W5LMcfoQJ3Ax2Rr wLypBnfo5P0wZiS8P9tB2bqwzI0dqokBRP0JoEWE6rknYqnYn4J1ATYUgoTh3huzTM9+ e86g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=CsdG25qL; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x64si12181650pfj.318.2018.04.08.20.09.31; Sun, 08 Apr 2018 20:10:08 -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=@microsoft.com header.s=selector1 header.b=CsdG25qL; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758039AbeDICev (ORCPT + 99 others); Sun, 8 Apr 2018 22:34:51 -0400 Received: from mail-sn1nam02on0101.outbound.protection.outlook.com ([104.47.36.101]:16522 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755602AbeDIA1j (ORCPT ); Sun, 8 Apr 2018 20:27:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=2Ddgc3wv0BgA+4wZmJ///QfhkNnPL1cDaS0l1tmnLjc=; b=CsdG25qLUWLLICsXqZ8m6Nk6uAUOO8Usl8ymbyPzJz/0g0ifwwW+ed9VhoMHDSeApDY+GdkfM51Db4U2BhNeNNFVqRXQQfdi6/gipKJvTDw2kJrGdhYLipP0v9dWhPwduSDqu1hkLxYGwmkOEYOe642cfYarGLqUpSZlz6wnCrY= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0871.namprd21.prod.outlook.com (10.167.110.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.2; Mon, 9 Apr 2018 00:27:34 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:27:34 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Chris Packham , Brian Norris , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 058/293] mtd: handle partitioning on devices with 0 erasesize Thread-Topic: [PATCH AUTOSEL for 4.9 058/293] mtd: handle partitioning on devices with 0 erasesize Thread-Index: AQHTz5kAgWMN5LdnDUOlZJ62Cebi8g== Date: Mon, 9 Apr 2018 00:23:36 +0000 Message-ID: <20180409002239.163177-58-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0871;7:+b0zTzfA9IC4YyeoyrZqN5Fh+4Xn/FUpESVE+J0i9sBKXfa/55mINMt8+ZaslT5huaNWOUxn0clRjtMOVUbJk3ELUC6Fsg9/Oas9g9hjWXXmqzcZIo+inWjSkngkJ9Yu2MxcVnC504H0Wcxf1lH4vaAi2/lI2La4E7oaBbJ7e0V5mTUTKRqwhHDVus2KbD0hC3CiEvyd7sQ554C2SHPc8RJy9sPJYYqQkCJD6gihfu8F7rC3cx0+gH2AiwsCWOdg;20:Ucm1UqzfM524+xIKIO9c4Bzv5l8VOyTE9QnFnxYyUZekhpZ5Lew6OUTzZfCjr5pjEBxWvYtfKdgT4dUT8E4bj8f0jqsTgADplebwOZeFGIyxCasrS09qOtCKPy0iRxVSeWHdT2B5UctpM5kKdXbCRyZKxguESW6CUHkokH6F8NE= X-MS-Office365-Filtering-Correlation-Id: 7e90a630-0db6-43d5-37d1-08d59db0b06d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB0871; x-ms-traffictypediagnostic: DM5PR2101MB0871: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(58145275503218); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0871;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0871; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(396003)(39380400002)(376002)(39860400002)(199004)(189003)(105586002)(8676002)(59450400001)(3660700001)(3280700002)(6506007)(81156014)(81166006)(14454004)(99286004)(72206003)(110136005)(8936002)(54906003)(305945005)(2906002)(316002)(10290500003)(478600001)(7736002)(53936002)(6512007)(486006)(11346002)(39060400002)(4326008)(86362001)(446003)(3846002)(102836004)(76176011)(476003)(25786009)(22452003)(36756003)(107886003)(10090500001)(5660300001)(6486002)(86612001)(6436002)(2616005)(68736007)(26005)(1076002)(186003)(2501003)(5250100002)(2900100001)(106356001)(66066001)(6116002)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0871;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ILoamaB9Q3l7HiqnKW7TfB8nX8gmTjRIl8nslztrMedKYUWGsd4CjJMn2klrfIgsU6N/7yOcdtNF86U/hmjoaCRVwU5j7zZhQKpQ3klxF7shdvCPnYmZPZ+aWhPi0vzy/cUZz58o5n1v19L9jhHcfAcvC+8Nk7KFrz/wm7tmlx6NmXHjv33GTVfN7pwT3z1JdfXFJ2p2kaWasbDYwJtYCjmZDlZoPcne4lDti4YkxcpwS/iB+GpT9sYWekccc0z7PJ0TZN8fEWNbCfWp4ZTpIObRIvZlGx5SzgBep0v8CQosLhtt1zrTBXqevhNNnxlsCTl3Z348Uf4M9UMGke5tAPsmdei8tptjGwiE8nyXSj1gRZP7t4vqwIh9y68+kCqBe/Hjyh6emnpH2LdmHVO+o/EYgBuwPg5YHZtMhvV7FIY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e90a630-0db6-43d5-37d1-08d59db0b06d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:36.7061 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0871 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chris Packham [ Upstream commit 1eeef2d7483a7e3f8d2dd2a5b9939b3b814dc549 ] erasesize is meaningful for flash devices but for SRAM there is no concept of an erase block so erasesize is set to 0. When partitioning these devices instead of ensuring partitions fall on erasesize boundaries we ensure they fall on writesize boundaries. Helped-by: Boris Brezillon Signed-off-by: Chris Packham Acked-by: Boris Brezillon Signed-off-by: Brian Norris Signed-off-by: Sasha Levin --- drivers/mtd/mtdpart.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index fccdd49bb964..4bb63503aabf 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -385,8 +385,12 @@ static struct mtd_part *allocate_partition(struct mtd_= info *master, const struct mtd_partition *part, int partno, uint64_t cur_offset) { + int wr_alignment =3D (master->flags & MTD_NO_ERASE) ? master->writesize: + master->erasesize; struct mtd_part *slave; + u32 remainder; char *name; + u64 tmp; =20 /* allocate the partition structure */ slave =3D kzalloc(sizeof(*slave), GFP_KERNEL); @@ -488,10 +492,11 @@ static struct mtd_part *allocate_partition(struct mtd= _info *master, if (slave->offset =3D=3D MTDPART_OFS_APPEND) slave->offset =3D cur_offset; if (slave->offset =3D=3D MTDPART_OFS_NXTBLK) { + tmp =3D cur_offset; slave->offset =3D cur_offset; - if (mtd_mod_by_eb(cur_offset, master) !=3D 0) { - /* Round up to next erasesize */ - slave->offset =3D (mtd_div_by_eb(cur_offset, master) + 1) * master->era= sesize; + remainder =3D do_div(tmp, wr_alignment); + if (remainder) { + slave->offset +=3D wr_alignment - remainder; printk(KERN_NOTICE "Moving partition %d: " "0x%012llx -> 0x%012llx\n", partno, (unsigned long long)cur_offset, (unsigned long long)slave->offse= t); @@ -556,19 +561,22 @@ static struct mtd_part *allocate_partition(struct mtd= _info *master, slave->mtd.erasesize =3D master->erasesize; } =20 - if ((slave->mtd.flags & MTD_WRITEABLE) && - mtd_mod_by_eb(slave->offset, &slave->mtd)) { + tmp =3D slave->offset; + remainder =3D do_div(tmp, wr_alignment); + if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) { /* Doesn't start on a boundary of major erase size */ /* FIXME: Let it be writable if it is on a boundary of * _minor_ erase size though */ slave->mtd.flags &=3D ~MTD_WRITEABLE; - printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase bloc= k boundary -- force read-only\n", + printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/writ= e block boundary -- force read-only\n", part->name); } - if ((slave->mtd.flags & MTD_WRITEABLE) && - mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) { + + tmp =3D slave->mtd.size; + remainder =3D do_div(tmp, wr_alignment); + if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) { slave->mtd.flags &=3D ~MTD_WRITEABLE; - printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block = -- force read-only\n", + printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write = block -- force read-only\n", part->name); } =20 --=20 2.15.1