Commit b8798636 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: storage_common: pass filesem to fsg_store_cdrom

If cdrom flag is set ro flag is implied. Try setting the ro first, and
only if it succeeds set the cdrom flag.
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 81a1d5ea
...@@ -3281,7 +3281,12 @@ static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page) ...@@ -3281,7 +3281,12 @@ static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page)
static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts,
const char *page, size_t len) const char *page, size_t len)
{ {
return fsg_store_cdrom(opts->lun, page, len); struct fsg_opts *fsg_opts;
fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom = static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom =
......
...@@ -371,6 +371,23 @@ ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) ...@@ -371,6 +371,23 @@ ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf)
} }
EXPORT_SYMBOL(fsg_show_removable); EXPORT_SYMBOL(fsg_show_removable);
/*
* The caller must hold fsg->filesem for reading when calling this function.
*/
static ssize_t _fsg_store_ro(struct fsg_lun *curlun, bool ro)
{
if (fsg_lun_is_open(curlun)) {
LDBG(curlun, "read-only status change prevented\n");
return -EBUSY;
}
curlun->ro = ro;
curlun->initially_ro = ro;
LDBG(curlun, "read-only status set to %d\n", curlun->ro);
return 0;
}
ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
const char *buf, size_t count) const char *buf, size_t count)
{ {
...@@ -386,16 +403,11 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, ...@@ -386,16 +403,11 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
* backing file is closed. * backing file is closed.
*/ */
down_read(filesem); down_read(filesem);
if (fsg_lun_is_open(curlun)) { rc = _fsg_store_ro(curlun, ro);
LDBG(curlun, "read-only status change prevented\n"); if (!rc)
rc = -EBUSY;
} else {
curlun->ro = ro;
curlun->initially_ro = ro;
LDBG(curlun, "read-only status set to %d\n", curlun->ro);
rc = count; rc = count;
}
up_read(filesem); up_read(filesem);
return rc; return rc;
} }
EXPORT_SYMBOL(fsg_store_ro); EXPORT_SYMBOL(fsg_store_ro);
...@@ -450,7 +462,8 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, ...@@ -450,7 +462,8 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
} }
EXPORT_SYMBOL(fsg_store_file); EXPORT_SYMBOL(fsg_store_file);
ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count) ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
const char *buf, size_t count)
{ {
bool cdrom; bool cdrom;
int ret; int ret;
...@@ -459,9 +472,16 @@ ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count) ...@@ -459,9 +472,16 @@ ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count)
if (ret) if (ret)
return ret; return ret;
curlun->cdrom = cdrom; down_read(filesem);
ret = cdrom ? _fsg_store_ro(curlun, true) : 0;
return count; if (!ret) {
curlun->cdrom = cdrom;
ret = count;
}
up_read(filesem);
return ret;
} }
EXPORT_SYMBOL(fsg_store_cdrom); EXPORT_SYMBOL(fsg_store_cdrom);
......
...@@ -221,7 +221,8 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, ...@@ -221,7 +221,8 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count); ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count);
ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
const char *buf, size_t count); const char *buf, size_t count);
ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count); ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
const char *buf, size_t count);
ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
size_t count); size_t count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment