Skip to content

Commit a10183d

Browse files
Christoph Hellwigaxboe
authored andcommitted
scsi: simplify scsi_partsize
Call scsi_bios_ptable from scsi_partsize instead of requiring boilerplate code in the callers. Also switch the calling convention to match that of the ->bios_param instances calling this function, and use true/false for the return value instead of the weird -1 convention. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 26ae353 commit a10183d

7 files changed

Lines changed: 46 additions & 95 deletions

File tree

‎Documentation/scsi/scsi_mid_low_api.txt‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ Summary:
299299
scsi_host_alloc - return a new scsi_host instance whose refcount==1
300300
scsi_host_get - increments Scsi_Host instance's refcount
301301
scsi_host_put - decrements Scsi_Host instance's refcount (free if 0)
302-
scsi_partsize - parse partition table into cylinders, heads + sectors
303302
scsi_register - create and register a scsi host adapter instance.
304303
scsi_remove_device - detach and remove a SCSI device
305304
scsi_remove_host - detach and remove all SCSI devices owned by host
@@ -472,26 +471,6 @@ void scsi_host_get(struct Scsi_Host *shost)
472471
void scsi_host_put(struct Scsi_Host *shost)
473472

474473

475-
/**
476-
* scsi_partsize - parse partition table into cylinders, heads + sectors
477-
* @buf: pointer to partition table
478-
* @capacity: size of (total) disk in 512 byte sectors
479-
* @cyls: outputs number of cylinders calculated via this pointer
480-
* @hds: outputs number of heads calculated via this pointer
481-
* @secs: outputs number of sectors calculated via this pointer
482-
*
483-
* Returns 0 on success, -1 on failure
484-
*
485-
* Might block: no
486-
*
487-
* Notes: Caller owns memory returned (free with kfree() )
488-
*
489-
* Defined in: drivers/scsi/scsicam.c
490-
**/
491-
int scsi_partsize(unsigned char *buf, unsigned long capacity,
492-
unsigned int *cyls, unsigned int *hds, unsigned int *secs)
493-
494-
495474
/**
496475
* scsi_register - create and register a scsi host adapter instance.
497476
* @sht: pointer to scsi host template

‎drivers/scsi/aic7xxx/aic79xx_osm.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,24 +723,17 @@ static int
723723
ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
724724
sector_t capacity, int geom[])
725725
{
726-
uint8_t *bh;
727726
int heads;
728727
int sectors;
729728
int cylinders;
730-
int ret;
731729
int extended;
732730
struct ahd_softc *ahd;
733731

734732
ahd = *((struct ahd_softc **)sdev->host->hostdata);
735733

736-
bh = scsi_bios_ptable(bdev);
737-
if (bh) {
738-
ret = scsi_partsize(bh, capacity,
739-
&geom[2], &geom[0], &geom[1]);
740-
kfree(bh);
741-
if (ret != -1)
742-
return (ret);
743-
}
734+
if (scsi_partsize(bdev, capacity, geom))
735+
return 0;
736+
744737
heads = 64;
745738
sectors = 32;
746739
cylinders = aic_sector_div(capacity, heads, sectors);

‎drivers/scsi/aic7xxx/aic7xxx_osm.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -695,26 +695,19 @@ static int
695695
ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
696696
sector_t capacity, int geom[])
697697
{
698-
uint8_t *bh;
699698
int heads;
700699
int sectors;
701700
int cylinders;
702-
int ret;
703701
int extended;
704702
struct ahc_softc *ahc;
705703
u_int channel;
706704

707705
ahc = *((struct ahc_softc **)sdev->host->hostdata);
708706
channel = sdev_channel(sdev);
709707

710-
bh = scsi_bios_ptable(bdev);
711-
if (bh) {
712-
ret = scsi_partsize(bh, capacity,
713-
&geom[2], &geom[0], &geom[1]);
714-
kfree(bh);
715-
if (ret != -1)
716-
return (ret);
717-
}
708+
if (scsi_partsize(bdev, capacity, geom))
709+
return 0;
710+
718711
heads = 64;
719712
sectors = 32;
720713
cylinders = aic_sector_div(capacity, heads, sectors);

‎drivers/scsi/arcmsr/arcmsr_hba.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,11 @@ static irqreturn_t arcmsr_do_interrupt(int irq, void *dev_id)
353353
static int arcmsr_bios_param(struct scsi_device *sdev,
354354
struct block_device *bdev, sector_t capacity, int *geom)
355355
{
356-
int ret, heads, sectors, cylinders, total_capacity;
357-
unsigned char *buffer;/* return copy of block device's partition table */
356+
int heads, sectors, cylinders, total_capacity;
357+
358+
if (scsi_partsize(bdev, capacity, geom))
359+
return 0;
358360

359-
buffer = scsi_bios_ptable(bdev);
360-
if (buffer) {
361-
ret = scsi_partsize(buffer, capacity, &geom[2], &geom[0], &geom[1]);
362-
kfree(buffer);
363-
if (ret != -1)
364-
return ret;
365-
}
366361
total_capacity = capacity;
367362
heads = 64;
368363
sectors = 32;

‎drivers/scsi/megaraid.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,11 +2795,9 @@ megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
27952795
sector_t capacity, int geom[])
27962796
{
27972797
adapter_t *adapter;
2798-
unsigned char *bh;
27992798
int heads;
28002799
int sectors;
28012800
int cylinders;
2802-
int rval;
28032801

28042802
/* Get pointer to host config structure */
28052803
adapter = (adapter_t *)sdev->host->hostdata;
@@ -2826,15 +2824,8 @@ megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
28262824
geom[2] = cylinders;
28272825
}
28282826
else {
2829-
bh = scsi_bios_ptable(bdev);
2830-
2831-
if( bh ) {
2832-
rval = scsi_partsize(bh, capacity,
2833-
&geom[2], &geom[0], &geom[1]);
2834-
kfree(bh);
2835-
if( rval != -1 )
2836-
return rval;
2837-
}
2827+
if (scsi_partsize(bdev, capacity, geom))
2828+
return 0;
28382829

28392830
dev_info(&adapter->dev->dev,
28402831
"invalid partition on this disk on channel %d\n",

‎drivers/scsi/scsicam.c‎

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,31 @@ EXPORT_SYMBOL(scsi_bios_ptable);
4848

4949
/**
5050
* scsi_partsize - Parse cylinders/heads/sectors from PC partition table
51-
* @buf: partition table, see scsi_bios_ptable()
51+
* @bdev: block device to parse
5252
* @capacity: size of the disk in sectors
53-
* @cyls: put cylinders here
54-
* @hds: put heads here
55-
* @secs: put sectors here
53+
* @geom: output in form of [hds, cylinders, sectors]
5654
*
5755
* Determine the BIOS mapping/geometry used to create the partition
58-
* table, storing the results in @cyls, @hds, and @secs
56+
* table, storing the results in @geom.
5957
*
60-
* Returns: -1 on failure, 0 on success.
58+
* Returns: %false on failure, %true on success.
6159
*/
62-
63-
int scsi_partsize(unsigned char *buf, unsigned long capacity,
64-
unsigned int *cyls, unsigned int *hds, unsigned int *secs)
60+
bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3])
6561
{
66-
struct partition *p = (struct partition *)buf, *largest = NULL;
67-
int i, largest_cyl;
6862
int cyl, ext_cyl, end_head, end_cyl, end_sector;
6963
unsigned int logical_end, physical_end, ext_physical_end;
64+
struct partition *p, *largest = NULL;
65+
void *buf;
66+
int ret = false;
7067

68+
buf = scsi_bios_ptable(bdev);
69+
if (!buf)
70+
return false;
7171

7272
if (*(unsigned short *) (buf + 64) == 0xAA55) {
73-
for (largest_cyl = -1, i = 0; i < 4; ++i, ++p) {
73+
int largest_cyl = -1, i;
74+
75+
for (i = 0, p = buf; i < 4; i++, p++) {
7476
if (!p->sys_ind)
7577
continue;
7678
#ifdef DEBUG
@@ -90,7 +92,7 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
9092
end_sector = largest->end_sector & 0x3f;
9193

9294
if (end_head + 1 == 0 || end_sector == 0)
93-
return -1;
95+
goto out_free_buf;
9496

9597
#ifdef DEBUG
9698
printk("scsicam_bios_param : end at h = %d, c = %d, s = %d\n",
@@ -115,19 +117,24 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
115117
,logical_end, physical_end, ext_physical_end, ext_cyl);
116118
#endif
117119

118-
if ((logical_end == physical_end) ||
119-
(end_cyl == 1023 && ext_physical_end == logical_end)) {
120-
*secs = end_sector;
121-
*hds = end_head + 1;
122-
*cyls = capacity / ((end_head + 1) * end_sector);
123-
return 0;
120+
if (logical_end == physical_end ||
121+
(end_cyl == 1023 && ext_physical_end == logical_end)) {
122+
geom[0] = end_head + 1;
123+
geom[1] = end_sector;
124+
geom[2] = (unsigned long)capacity /
125+
((end_head + 1) * end_sector);
126+
ret = true;
127+
goto out_free_buf;
124128
}
125129
#ifdef DEBUG
126130
printk("scsicam_bios_param : logical (%u) != physical (%u)\n",
127131
logical_end, physical_end);
128132
#endif
129133
}
130-
return -1;
134+
135+
out_free_buf:
136+
kfree(buf);
137+
return ret;
131138
}
132139
EXPORT_SYMBOL(scsi_partsize);
133140

@@ -210,20 +217,14 @@ static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds
210217
*/
211218
int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip)
212219
{
213-
unsigned char *p;
214220
u64 capacity64 = capacity; /* Suppress gcc warning */
215-
int ret;
216-
217-
p = scsi_bios_ptable(bdev);
218-
if (!p)
219-
return -1;
221+
int ret = 0;
220222

221223
/* try to infer mapping from partition table */
222-
ret = scsi_partsize(p, (unsigned long)capacity, (unsigned int *)ip + 2,
223-
(unsigned int *)ip + 0, (unsigned int *)ip + 1);
224-
kfree(p);
224+
if (scsi_partsize(bdev, capacity, ip))
225+
return 0;
225226

226-
if (ret == -1 && capacity64 < (1ULL << 32)) {
227+
if (capacity64 < (1ULL << 32)) {
227228
/*
228229
* Pick some standard mapping with at most 1024 cylinders, and
229230
* at most 62 sectors per track - this works up to 7905 MB.

‎include/scsi/scsicam.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
#ifndef SCSICAM_H
1515
#define SCSICAM_H
16-
extern int scsicam_bios_param (struct block_device *bdev, sector_t capacity, int *ip);
17-
extern int scsi_partsize(unsigned char *buf, unsigned long capacity,
18-
unsigned int *cyls, unsigned int *hds, unsigned int *secs);
19-
extern unsigned char *scsi_bios_ptable(struct block_device *bdev);
16+
int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip);
17+
bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3]);
18+
unsigned char *scsi_bios_ptable(struct block_device *bdev);
2019
#endif /* def SCSICAM_H */

0 commit comments

Comments
 (0)