Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1dac06b2 authored by Latchesar Ionkov's avatar Latchesar Ionkov Committed by Linus Torvalds
Browse files

[PATCH] v9fs: handle kthread_create failure, minor bugfixes



- remove unnecessary -ENOMEM assignments
- return correct value when buf_check_size for second time in a buffer
- handle failures when create_workqueue and kthread_create are called
- use kzalloc instead of kmalloc/memset 0
- v9fs_str_copy and v9fs_str_compare were buggy, were used only in one
  place, correct the logic and move it to the place it is used.

Signed-off-by: default avatarLatchesar Ionkov <lucho@ionkov.net>
Cc: Eric Van Hensbergen <ericvh@ericvh.myip.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 531b1094
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
	dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname,
		aname, fid, afid);

	ret = -ENOMEM;
	tc = v9fs_create_tattach(fid, afid, uname, aname);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -136,7 +135,6 @@ v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)

	dprintk(DEBUG_9P, "fid %d\n", fid);

	ret = -ENOMEM;
	rc = NULL;
	tc = v9fs_create_tclunk(fid);
	if (!IS_ERR(tc))
@@ -165,7 +163,6 @@ int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag)

	dprintk(DEBUG_9P, "oldtag %d\n", oldtag);

	ret = -ENOMEM;
	tc = v9fs_create_tflush(oldtag);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, NULL);
@@ -221,7 +218,6 @@ v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,

	dprintk(DEBUG_9P, "fid %d\n", fid);

	ret = -ENOMEM;
	tc = v9fs_create_twstat(fid, wstat, v9ses->extended);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -259,7 +255,6 @@ v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
	else
		nwname = 0;

	ret = -ENOMEM;
	tc = v9fs_create_twalk(fid, newfid, nwname, &name);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -289,7 +284,6 @@ v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,

	dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);

	ret = -ENOMEM;
	tc = v9fs_create_topen(fid, mode);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -317,7 +311,6 @@ v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,

	dprintk(DEBUG_9P, "fid %d\n", fid);

	ret = -ENOMEM;
	tc = v9fs_create_tremove(fid);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -349,7 +342,6 @@ v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
	dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
		fid, name, perm, mode);

	ret = -ENOMEM;
	tc = v9fs_create_tcreate(fid, name, perm, mode);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
@@ -380,7 +372,6 @@ v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
	dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
		(long long unsigned) offset, count);

	ret = -ENOMEM;
	tc = v9fs_create_tread(fid, offset, count);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
@@ -418,7 +409,6 @@ v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count,
	dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
		(long long unsigned) offset, count);

	ret = -ENOMEM;
	tc = v9fs_create_twrite(fid, offset, count, data);
	if (!IS_ERR(tc)) {
		ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
+0 −3
Original line number Diff line number Diff line
@@ -340,9 +340,6 @@ struct v9fs_fcall {
	fcall?fcall->params.rerror.error.len:0, \
	fcall?fcall->params.rerror.error.str:"");

char *v9fs_str_copy(char *buf, int buflen, struct v9fs_str *str);
int v9fs_str_compare(char *buf, struct v9fs_str *str);

int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
		   char *version, struct v9fs_fcall **rcall);

+9 −36
Original line number Diff line number Diff line
@@ -45,37 +45,6 @@ struct cbuf {
	unsigned char *ep;
};

char *v9fs_str_copy(char *buf, int buflen, struct v9fs_str *str)
{
	int n;

	if (buflen < str->len)
		n = buflen;
	else
		n = str->len;

	memmove(buf, str->str, n - 1);

	return buf;
}

int v9fs_str_compare(char *buf, struct v9fs_str *str)
{
	int n, ret;

	ret = strncmp(buf, str->str, str->len);

	if (!ret) {
		n = strlen(buf);
		if (n < str->len)
			ret = -1;
		else if (n > str->len)
			ret = 1;
	}

	return ret;
}

static inline void buf_init(struct cbuf *buf, void *data, int datalen)
{
	buf->sp = buf->p = data;
@@ -89,11 +58,14 @@ static inline int buf_check_overflow(struct cbuf *buf)

static inline int buf_check_size(struct cbuf *buf, int len)
{
	if (buf->p + len > buf->ep && buf->p < buf->ep) {
	if (buf->p + len > buf->ep) {
		if (buf->p < buf->ep) {
			eprintk(KERN_ERR, "buffer overflow: want %d has %d\n",
				len, (int)(buf->ep - buf->p));
			dump_stack();
			buf->p = buf->ep + 1;
		}

		return 0;
	}

@@ -527,6 +499,7 @@ v9fs_create_common(struct cbuf *bufp, u32 size, u8 id)

void v9fs_set_tag(struct v9fs_fcall *fc, u16 tag)
{
	fc->tag = tag;
	*(__le16 *) (fc->sdata + 5) = cpu_to_le16(tag);
}

+0 −1
Original line number Diff line number Diff line
@@ -176,4 +176,3 @@ static struct errormap errmap[] = {
};

extern int v9fs_error_init(void);
extern int v9fs_errstr2errno(char *errstr, int len);
+26 −12
Original line number Diff line number Diff line
@@ -102,8 +102,6 @@ struct v9fs_mux_rpc {
	wait_queue_head_t wqueue;
};

extern int v9fs_errstr2errno(char *str, int len);

static int v9fs_poll_proc(void *);
static void v9fs_read_work(void *);
static void v9fs_write_work(void *);
@@ -119,7 +117,7 @@ static int v9fs_mux_num;
static int v9fs_mux_poll_task_num;
static struct v9fs_mux_poll_task v9fs_mux_poll_tasks[100];

void v9fs_mux_global_init(void)
int v9fs_mux_global_init(void)
{
	int i;

@@ -127,6 +125,10 @@ void v9fs_mux_global_init(void)
		v9fs_mux_poll_tasks[i].task = NULL;

	v9fs_mux_wq = create_workqueue("v9fs");
	if (!v9fs_mux_wq)
		return -ENOMEM;

	return 0;
}

void v9fs_mux_global_exit(void)
@@ -156,10 +158,11 @@ inline int v9fs_mux_calc_poll_procs(int muxnum)
	return n;
}

static void v9fs_mux_poll_start(struct v9fs_mux_data *m)
static int v9fs_mux_poll_start(struct v9fs_mux_data *m)
{
	int i, n;
	struct v9fs_mux_poll_task *vpt, *vptlast;
	struct task_struct *pproc;

	dprintk(DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, v9fs_mux_num,
		v9fs_mux_poll_task_num);
@@ -171,13 +174,16 @@ static void v9fs_mux_poll_start(struct v9fs_mux_data *m)
			if (v9fs_mux_poll_tasks[i].task == NULL) {
				vpt = &v9fs_mux_poll_tasks[i];
				dprintk(DEBUG_MUX, "create proc %p\n", vpt);
				vpt->task =
				    kthread_create(v9fs_poll_proc, vpt,
				pproc = kthread_create(v9fs_poll_proc, vpt,
						   "v9fs-poll");

				if (!IS_ERR(pproc)) {
					vpt->task = pproc;
					INIT_LIST_HEAD(&vpt->mux_list);
					vpt->muxnum = 0;
					v9fs_mux_poll_task_num++;
					wake_up_process(vpt->task);
				}
				break;
			}
		}
@@ -207,16 +213,21 @@ static void v9fs_mux_poll_start(struct v9fs_mux_data *m)
	}

	if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) {
		if (vptlast == NULL)
			return -ENOMEM;

		dprintk(DEBUG_MUX, "put in proc %d\n", i);
		list_add(&m->mux_list, &vptlast->mux_list);
		vptlast->muxnum++;
		m->poll_task = vpt;
		m->poll_task = vptlast;
		memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
		init_poll_funcptr(&m->pt, v9fs_pollwait);
	}

	v9fs_mux_num++;
	down(&v9fs_mux_task_lock);

	return 0;
}

static void v9fs_mux_poll_stop(struct v9fs_mux_data *m)
@@ -283,7 +294,10 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
	INIT_WORK(&m->wq, v9fs_write_work, m);
	m->wsched = 0;
	memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
	v9fs_mux_poll_start(m);
	m->poll_task = NULL;
	n = v9fs_mux_poll_start(m);
	if (n)
		return ERR_PTR(n);

	n = trans->poll(trans, &m->pt);
	if (n & POLLIN) {
Loading