Skip to content

Commit 17017d8

Browse files
oakadtorvalds
authored andcommitted
memstick: add "start" and "stop" methods to memstick device
In some cases it may be desirable to ensure that associated driver is not going to access the media in some period of time. "start" and "stop" methods are provided therefore to allow it. Signed-off-by: Alex Dubov <oakad@yahoo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b778999 commit 17017d8

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

‎drivers/memstick/core/memstick.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ static void memstick_check(struct work_struct *work)
433433

434434
dev_dbg(&host->dev, "memstick_check started\n");
435435
mutex_lock(&host->lock);
436-
if (!host->card)
437-
memstick_power_on(host);
436+
if (!host->card) {
437+
if (memstick_power_on(host))
438+
goto out_power_off;
439+
} else
440+
host->card->stop(host->card);
438441

439442
card = memstick_alloc_card(host);
440443

@@ -452,7 +455,8 @@ static void memstick_check(struct work_struct *work)
452455
|| !(host->card->check(host->card))) {
453456
device_unregister(&host->card->dev);
454457
host->card = NULL;
455-
}
458+
} else
459+
host->card->start(host->card);
456460
}
457461

458462
if (!host->card) {
@@ -465,6 +469,7 @@ static void memstick_check(struct work_struct *work)
465469
kfree(card);
466470
}
467471

472+
out_power_off:
468473
if (!host->card)
469474
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
470475

‎drivers/memstick/core/mspro_block.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,37 @@ static int mspro_block_has_request(struct mspro_block_data *msb)
752752
return rc;
753753
}
754754

755+
static void mspro_block_stop(struct memstick_dev *card)
756+
{
757+
struct mspro_block_data *msb = memstick_get_drvdata(card);
758+
int rc = 0;
759+
unsigned long flags;
760+
761+
while (1) {
762+
spin_lock_irqsave(&msb->q_lock, flags);
763+
if (!msb->has_request) {
764+
blk_stop_queue(msb->queue);
765+
rc = 1;
766+
}
767+
spin_unlock_irqrestore(&msb->q_lock, flags);
768+
769+
if (rc)
770+
break;
771+
772+
wait_for_completion(&card->mrq_complete);
773+
}
774+
}
775+
776+
static void mspro_block_start(struct memstick_dev *card)
777+
{
778+
struct mspro_block_data *msb = memstick_get_drvdata(card);
779+
unsigned long flags;
780+
781+
spin_lock_irqsave(&msb->q_lock, flags);
782+
blk_start_queue(msb->queue);
783+
spin_unlock_irqrestore(&msb->q_lock, flags);
784+
}
785+
755786
static int mspro_block_queue_thread(void *data)
756787
{
757788
struct memstick_dev *card = data;
@@ -1272,6 +1303,8 @@ static int mspro_block_probe(struct memstick_dev *card)
12721303
rc = mspro_block_init_disk(card);
12731304
if (!rc) {
12741305
card->check = mspro_block_check_card;
1306+
card->stop = mspro_block_stop;
1307+
card->start = mspro_block_start;
12751308
return 0;
12761309
}
12771310

‎include/linux/memstick.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ struct memstick_dev {
263263
/* Get next request from the media driver. */
264264
int (*next_request)(struct memstick_dev *card,
265265
struct memstick_request **mrq);
266+
/* Tell the media driver to stop doing things */
267+
void (*stop)(struct memstick_dev *card);
268+
/* Allow the media driver to continue */
269+
void (*start)(struct memstick_dev *card);
266270

267271
struct device dev;
268272
};

0 commit comments

Comments
 (0)