hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/mtd/ubi/block.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2014 Ezequiel Garcia
34 * Copyright (c) 2011 Free Electrons
....@@ -6,15 +7,6 @@
67 * Copyright (c) International Business Machines Corp., 2006
78 * Copyright (c) Nokia Corporation, 2007
89 * Authors: Artem Bityutskiy, Frank Haverkamp
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation, version 2.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17
- * the GNU General Public License for more details.
1810 */
1911
2012 /*
....@@ -353,15 +345,36 @@
353345 .init_request = ubiblock_init_request,
354346 };
355347
348
+static int calc_disk_capacity(struct ubi_volume_info *vi, u64 *disk_capacity)
349
+{
350
+ u64 size = vi->used_bytes >> 9;
351
+
352
+ if (vi->used_bytes % 512) {
353
+ pr_warn("UBI: block: volume size is not a multiple of 512, "
354
+ "last %llu bytes are ignored!\n",
355
+ vi->used_bytes - (size << 9));
356
+ }
357
+
358
+ if ((sector_t)size != size)
359
+ return -EFBIG;
360
+
361
+ *disk_capacity = size;
362
+
363
+ return 0;
364
+}
365
+
356366 int ubiblock_create(struct ubi_volume_info *vi)
357367 {
358368 struct ubiblock *dev;
359369 struct gendisk *gd;
360
- u64 disk_capacity = vi->used_bytes >> 9;
370
+ u64 disk_capacity;
361371 int ret;
362372
363
- if ((sector_t)disk_capacity != disk_capacity)
364
- return -EFBIG;
373
+ ret = calc_disk_capacity(vi, &disk_capacity);
374
+ if (ret) {
375
+ return ret;
376
+ }
377
+
365378 /* Check that the volume isn't already handled */
366379 mutex_lock(&devices_mutex);
367380 if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
....@@ -515,7 +528,8 @@
515528 static int ubiblock_resize(struct ubi_volume_info *vi)
516529 {
517530 struct ubiblock *dev;
518
- u64 disk_capacity = vi->used_bytes >> 9;
531
+ u64 disk_capacity;
532
+ int ret;
519533
520534 /*
521535 * Need to lock the device list until we stop using the device,
....@@ -528,11 +542,16 @@
528542 mutex_unlock(&devices_mutex);
529543 return -ENODEV;
530544 }
531
- if ((sector_t)disk_capacity != disk_capacity) {
545
+
546
+ ret = calc_disk_capacity(vi, &disk_capacity);
547
+ if (ret) {
532548 mutex_unlock(&devices_mutex);
533
- dev_warn(disk_to_dev(dev->gd), "the volume is too big (%d LEBs), cannot resize",
534
- vi->size);
535
- return -EFBIG;
549
+ if (ret == -EFBIG) {
550
+ dev_warn(disk_to_dev(dev->gd),
551
+ "the volume is too big (%d LEBs), cannot resize",
552
+ vi->size);
553
+ }
554
+ return ret;
536555 }
537556
538557 mutex_lock(&dev->dev_mutex);