* [PATCH 0/5] net/9p: Fine-tuning for some function implementations @ 2017-08-15 11:56 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 11:56 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 13:43:21 +0200 Some update suggestions were taken into account from static source code analysis. Markus Elfring (5): Delete an error message for a failed memory allocation in five functions Improve 19 size determinations Add a jump target in p9_client_walk() Adjust a jump target in p9_client_attach() Delete an unnecessary variable initialisation in p9_client_attach() net/9p/client.c | 51 +++++++++++++++++++++------------------------------ net/9p/protocol.c | 6 +++--- net/9p/trans_fd.c | 16 +++++++--------- net/9p/trans_rdma.c | 8 +++----- net/9p/trans_virtio.c | 6 ++---- net/9p/util.c | 2 +- 6 files changed, 37 insertions(+), 52 deletions(-) -- 2.14.0 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/5] net/9p: Fine-tuning for some function implementations @ 2017-08-15 11:56 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 11:56 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 13:43:21 +0200 Some update suggestions were taken into account from static source code analysis. Markus Elfring (5): Delete an error message for a failed memory allocation in five functions Improve 19 size determinations Add a jump target in p9_client_walk() Adjust a jump target in p9_client_attach() Delete an unnecessary variable initialisation in p9_client_attach() net/9p/client.c | 51 +++++++++++++++++++++------------------------------ net/9p/protocol.c | 6 +++--- net/9p/trans_fd.c | 16 +++++++--------- net/9p/trans_rdma.c | 8 +++----- net/9p/trans_virtio.c | 6 ++---- net/9p/util.c | 2 +- 6 files changed, 37 insertions(+), 52 deletions(-) -- 2.14.0 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/5] net/9p: Delete an error message for a failed memory allocation in five functions 2017-08-15 11:56 ` SF Markus Elfring @ 2017-08-15 11:58 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 11:58 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 08:25:41 +0200 Omit an extra message for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 7 ++----- net/9p/trans_fd.c | 6 ++---- net/9p/trans_rdma.c | 6 ++---- net/9p/trans_virtio.c | 1 - 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 4674235b0d9b..2273181e9ba9 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -160,11 +160,9 @@ static int parse_opts(char *opts, struct p9_client *clnt) return 0; tmp_options = kstrdup(opts, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { @@ -277,7 +275,6 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size) sizeof(struct p9_req_t), GFP_ATOMIC); if (!c->reqs[row]) { - pr_err("Couldn't grow tag array\n"); spin_unlock_irqrestore(&c->lock, flags); return ERR_PTR(-ENOMEM); } diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index ddfa86648f95..3c272e5bc9ea 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -762,11 +762,9 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) return 0; tmp_options = kstrdup(params, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index 6d8e3031978f..f98b6aae308b 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -205,11 +205,9 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts) return 0; tmp_options = kstrdup(params, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index f24b25c25106..8a2cf9748398 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -552,7 +552,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); if (!chan) { - pr_err("Failed to allocate virtio 9P channel\n"); err = -ENOMEM; goto fail; } -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 1/5] net/9p: Delete an error message for a failed memory allocation in five functions @ 2017-08-15 11:58 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 11:58 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 08:25:41 +0200 Omit an extra message for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 7 ++----- net/9p/trans_fd.c | 6 ++---- net/9p/trans_rdma.c | 6 ++---- net/9p/trans_virtio.c | 1 - 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 4674235b0d9b..2273181e9ba9 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -160,11 +160,9 @@ static int parse_opts(char *opts, struct p9_client *clnt) return 0; tmp_options = kstrdup(opts, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { @@ -277,7 +275,6 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size) sizeof(struct p9_req_t), GFP_ATOMIC); if (!c->reqs[row]) { - pr_err("Couldn't grow tag array\n"); spin_unlock_irqrestore(&c->lock, flags); return ERR_PTR(-ENOMEM); } diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index ddfa86648f95..3c272e5bc9ea 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -762,11 +762,9 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) return 0; tmp_options = kstrdup(params, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index 6d8e3031978f..f98b6aae308b 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -205,11 +205,9 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts) return 0; tmp_options = kstrdup(params, GFP_KERNEL); - if (!tmp_options) { - p9_debug(P9_DEBUG_ERROR, - "failed to allocate copy of option string\n"); + if (!tmp_options) return -ENOMEM; - } + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index f24b25c25106..8a2cf9748398 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -552,7 +552,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); if (!chan) { - pr_err("Failed to allocate virtio 9P channel\n"); err = -ENOMEM; goto fail; } -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/5] net/9p: Improve 19 size determinations 2017-08-15 11:56 ` SF Markus Elfring @ 2017-08-15 12:00 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:00 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 09:36:20 +0200 Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 19 +++++++++---------- net/9p/protocol.c | 6 +++--- net/9p/trans_fd.c | 10 +++++----- net/9p/trans_rdma.c | 2 +- net/9p/trans_virtio.c | 5 ++--- net/9p/util.c | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 2273181e9ba9..2ca55d4b0b7d 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -272,8 +272,8 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size) while (tag >= c->max_tag) { row = (tag / P9_ROW_MAXTAG); c->reqs[row] = kcalloc(P9_ROW_MAXTAG, - sizeof(struct p9_req_t), GFP_ATOMIC); - + sizeof(*c->reqs[row]), + GFP_ATOMIC); if (!c->reqs[row]) { spin_unlock_irqrestore(&c->lock, flags); return ERR_PTR(-ENOMEM); @@ -907,7 +907,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) unsigned long flags; p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt); - fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL); + fid = kmalloc(sizeof(*fid), GFP_KERNEL); if (!fid) return ERR_PTR(-ENOMEM); @@ -918,7 +918,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) } fid->fid = ret; - memset(&fid->qid, 0, sizeof(struct p9_qid)); + memset(&fid->qid, 0, sizeof(fid->qid)); fid->mode = -1; fid->uid = current_fsuid(); fid->clnt = clnt; @@ -1015,7 +1015,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) char *client_id; err = 0; - clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); + clnt = kmalloc(sizeof(*clnt), GFP_KERNEL); if (!clnt) return ERR_PTR(-ENOMEM); @@ -1157,7 +1157,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_debug(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", qid.type, (unsigned long long)qid.path, qid.version); - memmove(&fid->qid, &qid, sizeof(struct p9_qid)); + memmove(&fid->qid, &qid, sizeof(qid)); p9_free_req(clnt, req); return fid; @@ -1227,7 +1227,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, wqids[count].version); if (nwname) - memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); + memmove(&fid->qid, &wqids[nwqids - 1], sizeof(fid->qid)); else fid->qid = oldfid->qid; @@ -1697,7 +1697,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid) { int err; struct p9_client *clnt; - struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL); + struct p9_wstat *ret = kmalloc(sizeof(*ret), GFP_KERNEL); struct p9_req_t *req; u16 ignored; @@ -1749,8 +1749,7 @@ struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, { int err; struct p9_client *clnt; - struct p9_stat_dotl *ret = kmalloc(sizeof(struct p9_stat_dotl), - GFP_KERNEL); + struct p9_stat_dotl *ret = kmalloc(sizeof(*ret), GFP_KERNEL); struct p9_req_t *req; p9_debug(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 16e10680518c..b8dc30f7de07 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -200,7 +200,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, struct p9_wstat *stbuf = va_arg(ap, struct p9_wstat *); - memset(stbuf, 0, sizeof(struct p9_wstat)); + memset(stbuf, 0, sizeof(*stbuf)); stbuf->n_uid = stbuf->n_muid = INVALID_UID; stbuf->n_gid = INVALID_GID; @@ -286,7 +286,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, if (!errcode) { *wqids = kmalloc(*nwqid * - sizeof(struct p9_qid), + sizeof(**wqids), GFP_NOFS); if (*wqids == NULL) errcode = -ENOMEM; @@ -316,7 +316,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, struct p9_stat_dotl *stbuf = va_arg(ap, struct p9_stat_dotl *); - memset(stbuf, 0, sizeof(struct p9_stat_dotl)); + memset(stbuf, 0, sizeof(*stbuf)); errcode = p9pdu_readf(pdu, proto_version, "qQdugqqqqqqqqqqqqqqq", diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 3c272e5bc9ea..4a709146ae24 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -805,8 +805,8 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) static int p9_fd_open(struct p9_client *client, int rfd, int wfd) { - struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd), - GFP_KERNEL); + struct p9_trans_fd *ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) return -ENOMEM; @@ -832,7 +832,7 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) struct p9_trans_fd *p; struct file *file; - p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); + p = kzalloc(sizeof(*p), GFP_KERNEL); if (!p) return -ENOMEM; @@ -983,7 +983,7 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args) err = csocket->ops->connect(csocket, (struct sockaddr *)&sin_server, - sizeof(struct sockaddr_in), 0); + sizeof(sin_server), 0); if (err < 0) { pr_err("%s (%d): problem connecting socket to %s\n", __func__, task_pid_nr(current), addr); @@ -1020,7 +1020,7 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args) return err; } err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, - sizeof(struct sockaddr_un) - 1, 0); + sizeof(sun_server) - 1, 0); if (err < 0) { pr_err("%s (%d): problem connecting socket: %s: %d\n", __func__, task_pid_nr(current), addr, err); diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index f98b6aae308b..6422a3775ff5 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -576,7 +576,7 @@ static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts) { struct p9_trans_rdma *rdma; - rdma = kzalloc(sizeof(struct p9_trans_rdma), GFP_KERNEL); + rdma = kzalloc(sizeof(*rdma), GFP_KERNEL); if (!rdma) return NULL; diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 8a2cf9748398..ac6ad9d344a6 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -359,8 +359,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan, nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) - (unsigned long)p / PAGE_SIZE; - - *pages = kmalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); + *pages = kmalloc(sizeof(**pages) * nr_pages, GFP_NOFS); if (!*pages) return -ENOMEM; @@ -550,7 +549,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) return -EINVAL; } - chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); + chan = kmalloc(sizeof(*chan), GFP_KERNEL); if (!chan) { err = -ENOMEM; goto fail; diff --git a/net/9p/util.c b/net/9p/util.c index 59f278e64f58..2c53173bdf1c 100644 --- a/net/9p/util.c +++ b/net/9p/util.c @@ -54,7 +54,7 @@ struct p9_idpool *p9_idpool_create(void) { struct p9_idpool *p; - p = kmalloc(sizeof(struct p9_idpool), GFP_KERNEL); + p = kmalloc(sizeof(*p), GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/5] net/9p: Improve 19 size determinations @ 2017-08-15 12:00 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:00 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 09:36:20 +0200 Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 19 +++++++++---------- net/9p/protocol.c | 6 +++--- net/9p/trans_fd.c | 10 +++++----- net/9p/trans_rdma.c | 2 +- net/9p/trans_virtio.c | 5 ++--- net/9p/util.c | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 2273181e9ba9..2ca55d4b0b7d 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -272,8 +272,8 @@ p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size) while (tag >= c->max_tag) { row = (tag / P9_ROW_MAXTAG); c->reqs[row] = kcalloc(P9_ROW_MAXTAG, - sizeof(struct p9_req_t), GFP_ATOMIC); - + sizeof(*c->reqs[row]), + GFP_ATOMIC); if (!c->reqs[row]) { spin_unlock_irqrestore(&c->lock, flags); return ERR_PTR(-ENOMEM); @@ -907,7 +907,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) unsigned long flags; p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt); - fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL); + fid = kmalloc(sizeof(*fid), GFP_KERNEL); if (!fid) return ERR_PTR(-ENOMEM); @@ -918,7 +918,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) } fid->fid = ret; - memset(&fid->qid, 0, sizeof(struct p9_qid)); + memset(&fid->qid, 0, sizeof(fid->qid)); fid->mode = -1; fid->uid = current_fsuid(); fid->clnt = clnt; @@ -1015,7 +1015,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) char *client_id; err = 0; - clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); + clnt = kmalloc(sizeof(*clnt), GFP_KERNEL); if (!clnt) return ERR_PTR(-ENOMEM); @@ -1157,7 +1157,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_debug(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", qid.type, (unsigned long long)qid.path, qid.version); - memmove(&fid->qid, &qid, sizeof(struct p9_qid)); + memmove(&fid->qid, &qid, sizeof(qid)); p9_free_req(clnt, req); return fid; @@ -1227,7 +1227,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, wqids[count].version); if (nwname) - memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); + memmove(&fid->qid, &wqids[nwqids - 1], sizeof(fid->qid)); else fid->qid = oldfid->qid; @@ -1697,7 +1697,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid) { int err; struct p9_client *clnt; - struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL); + struct p9_wstat *ret = kmalloc(sizeof(*ret), GFP_KERNEL); struct p9_req_t *req; u16 ignored; @@ -1749,8 +1749,7 @@ struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, { int err; struct p9_client *clnt; - struct p9_stat_dotl *ret = kmalloc(sizeof(struct p9_stat_dotl), - GFP_KERNEL); + struct p9_stat_dotl *ret = kmalloc(sizeof(*ret), GFP_KERNEL); struct p9_req_t *req; p9_debug(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 16e10680518c..b8dc30f7de07 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -200,7 +200,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, struct p9_wstat *stbuf va_arg(ap, struct p9_wstat *); - memset(stbuf, 0, sizeof(struct p9_wstat)); + memset(stbuf, 0, sizeof(*stbuf)); stbuf->n_uid = stbuf->n_muid = INVALID_UID; stbuf->n_gid = INVALID_GID; @@ -286,7 +286,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, if (!errcode) { *wqids kmalloc(*nwqid * - sizeof(struct p9_qid), + sizeof(**wqids), GFP_NOFS); if (*wqids = NULL) errcode = -ENOMEM; @@ -316,7 +316,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, struct p9_stat_dotl *stbuf va_arg(ap, struct p9_stat_dotl *); - memset(stbuf, 0, sizeof(struct p9_stat_dotl)); + memset(stbuf, 0, sizeof(*stbuf)); errcode p9pdu_readf(pdu, proto_version, "qQdugqqqqqqqqqqqqqqq", diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 3c272e5bc9ea..4a709146ae24 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -805,8 +805,8 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) static int p9_fd_open(struct p9_client *client, int rfd, int wfd) { - struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd), - GFP_KERNEL); + struct p9_trans_fd *ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) return -ENOMEM; @@ -832,7 +832,7 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) struct p9_trans_fd *p; struct file *file; - p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); + p = kzalloc(sizeof(*p), GFP_KERNEL); if (!p) return -ENOMEM; @@ -983,7 +983,7 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args) err = csocket->ops->connect(csocket, (struct sockaddr *)&sin_server, - sizeof(struct sockaddr_in), 0); + sizeof(sin_server), 0); if (err < 0) { pr_err("%s (%d): problem connecting socket to %s\n", __func__, task_pid_nr(current), addr); @@ -1020,7 +1020,7 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args) return err; } err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, - sizeof(struct sockaddr_un) - 1, 0); + sizeof(sun_server) - 1, 0); if (err < 0) { pr_err("%s (%d): problem connecting socket: %s: %d\n", __func__, task_pid_nr(current), addr, err); diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index f98b6aae308b..6422a3775ff5 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -576,7 +576,7 @@ static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts) { struct p9_trans_rdma *rdma; - rdma = kzalloc(sizeof(struct p9_trans_rdma), GFP_KERNEL); + rdma = kzalloc(sizeof(*rdma), GFP_KERNEL); if (!rdma) return NULL; diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 8a2cf9748398..ac6ad9d344a6 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -359,8 +359,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan, nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) - (unsigned long)p / PAGE_SIZE; - - *pages = kmalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); + *pages = kmalloc(sizeof(**pages) * nr_pages, GFP_NOFS); if (!*pages) return -ENOMEM; @@ -550,7 +549,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) return -EINVAL; } - chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); + chan = kmalloc(sizeof(*chan), GFP_KERNEL); if (!chan) { err = -ENOMEM; goto fail; diff --git a/net/9p/util.c b/net/9p/util.c index 59f278e64f58..2c53173bdf1c 100644 --- a/net/9p/util.c +++ b/net/9p/util.c @@ -54,7 +54,7 @@ struct p9_idpool *p9_idpool_create(void) { struct p9_idpool *p; - p = kmalloc(sizeof(struct p9_idpool), GFP_KERNEL); + p = kmalloc(sizeof(*p), GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] net/9p: Improve 19 size determinations 2017-08-15 12:00 ` SF Markus Elfring @ 2017-08-15 14:21 ` Al Viro -1 siblings, 0 replies; 14+ messages in thread From: Al Viro @ 2017-08-15 14:21 UTC (permalink / raw) To: SF Markus Elfring Cc: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich, LKML, kernel-janitors On Tue, Aug 15, 2017 at 02:00:06PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 15 Aug 2017 09:36:20 +0200 > > Replace the specification of data structures by variable references > as the parameter for the operator "sizeof" to make the corresponding size > determination a bit safer according to the Linux coding style convention. Garbage. This makes it so much harder to find where the objects of given type are created. It's _not_ safer and any patches of that sort around VFS will be shitcanned. What to do with net/9p patches is up to net/9p maintainers, but I would strongly recommend the same treatment. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] net/9p: Improve 19 size determinations @ 2017-08-15 14:21 ` Al Viro 0 siblings, 0 replies; 14+ messages in thread From: Al Viro @ 2017-08-15 14:21 UTC (permalink / raw) To: SF Markus Elfring Cc: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich, LKML, kernel-janitors On Tue, Aug 15, 2017 at 02:00:06PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 15 Aug 2017 09:36:20 +0200 > > Replace the specification of data structures by variable references > as the parameter for the operator "sizeof" to make the corresponding size > determination a bit safer according to the Linux coding style convention. Garbage. This makes it so much harder to find where the objects of given type are created. It's _not_ safer and any patches of that sort around VFS will be shitcanned. What to do with net/9p patches is up to net/9p maintainers, but I would strongly recommend the same treatment. ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/5] net/9p: Add a jump target in p9_client_walk() 2017-08-15 11:56 ` SF Markus Elfring @ 2017-08-15 12:01 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:01 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 10:07:22 +0200 Replace a variable assignment by a goto statement so that an extra check will be avoided at the end of this function. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 2ca55d4b0b7d..6c2fc796edfb 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1237,12 +1237,11 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, clunk_fid: kfree(wqids); p9_client_clunk(fid); - fid = NULL; - + goto exit; error: if (fid && (fid != oldfid)) p9_fid_destroy(fid); - +exit: return ERR_PTR(err); } EXPORT_SYMBOL(p9_client_walk); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/5] net/9p: Add a jump target in p9_client_walk() @ 2017-08-15 12:01 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:01 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 10:07:22 +0200 Replace a variable assignment by a goto statement so that an extra check will be avoided at the end of this function. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 2ca55d4b0b7d..6c2fc796edfb 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1237,12 +1237,11 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, clunk_fid: kfree(wqids); p9_client_clunk(fid); - fid = NULL; - + goto exit; error: if (fid && (fid != oldfid)) p9_fid_destroy(fid); - +exit: return ERR_PTR(err); } EXPORT_SYMBOL(p9_client_walk); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/5] net/9p: Adjust a jump target in p9_client_attach() 2017-08-15 11:56 ` SF Markus Elfring @ 2017-08-15 12:02 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:02 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 11:17:23 +0200 Adjust jump labels so that the function implementation becomes smaller. Delete an extra variable assignment and a check (at the end of this function). Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 6c2fc796edfb..38c08171acc6 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1133,25 +1133,23 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_debug(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n", afid ? afid->fid : -1, uname, aname); fid = p9_fid_create(clnt); - if (IS_ERR(fid)) { - err = PTR_ERR(fid); - fid = NULL; - goto error; - } + if (IS_ERR(fid)) + return fid; + fid->uid = n_uname; req = p9_client_rpc(clnt, P9_TATTACH, "ddss?u", fid->fid, afid ? afid->fid : P9_NOFID, uname, aname, n_uname); if (IS_ERR(req)) { err = PTR_ERR(req); - goto error; + goto destroy_fid; } err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); if (err) { trace_9p_protocol_dump(clnt, req->rc); p9_free_req(clnt, req); - goto error; + goto destroy_fid; } p9_debug(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", @@ -1161,10 +1159,8 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_free_req(clnt, req); return fid; - -error: - if (fid) - p9_fid_destroy(fid); +destroy_fid: + p9_fid_destroy(fid); return ERR_PTR(err); } EXPORT_SYMBOL(p9_client_attach); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/5] net/9p: Adjust a jump target in p9_client_attach() @ 2017-08-15 12:02 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:02 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 11:17:23 +0200 Adjust jump labels so that the function implementation becomes smaller. Delete an extra variable assignment and a check (at the end of this function). Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 6c2fc796edfb..38c08171acc6 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1133,25 +1133,23 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_debug(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n", afid ? afid->fid : -1, uname, aname); fid = p9_fid_create(clnt); - if (IS_ERR(fid)) { - err = PTR_ERR(fid); - fid = NULL; - goto error; - } + if (IS_ERR(fid)) + return fid; + fid->uid = n_uname; req = p9_client_rpc(clnt, P9_TATTACH, "ddss?u", fid->fid, afid ? afid->fid : P9_NOFID, uname, aname, n_uname); if (IS_ERR(req)) { err = PTR_ERR(req); - goto error; + goto destroy_fid; } err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); if (err) { trace_9p_protocol_dump(clnt, req->rc); p9_free_req(clnt, req); - goto error; + goto destroy_fid; } p9_debug(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", @@ -1161,10 +1159,8 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, p9_free_req(clnt, req); return fid; - -error: - if (fid) - p9_fid_destroy(fid); +destroy_fid: + p9_fid_destroy(fid); return ERR_PTR(err); } EXPORT_SYMBOL(p9_client_attach); -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/5] net/9p: Delete an unnecessary variable initialisation in p9_client_attach() 2017-08-15 11:56 ` SF Markus Elfring @ 2017-08-15 12:03 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:03 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 11:25:31 +0200 The local variable "err" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index 38c08171acc6..1d59db9aafb3 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1124,7 +1124,7 @@ EXPORT_SYMBOL(p9_client_begin_disconnect); struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, const char *uname, kuid_t n_uname, const char *aname) { - int err = 0; + int err; struct p9_req_t *req; struct p9_fid *fid; struct p9_qid qid; -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/5] net/9p: Delete an unnecessary variable initialisation in p9_client_attach() @ 2017-08-15 12:03 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2017-08-15 12:03 UTC (permalink / raw) To: v9fs-developer, netdev, David S. Miller, Eric Van Hensbergen, Latchesar Ionkov, Ron Minnich Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 15 Aug 2017 11:25:31 +0200 The local variable "err" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/9p/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index 38c08171acc6..1d59db9aafb3 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1124,7 +1124,7 @@ EXPORT_SYMBOL(p9_client_begin_disconnect); struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, const char *uname, kuid_t n_uname, const char *aname) { - int err = 0; + int err; struct p9_req_t *req; struct p9_fid *fid; struct p9_qid qid; -- 2.14.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-08-15 14:22 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-08-15 11:56 [PATCH 0/5] net/9p: Fine-tuning for some function implementations SF Markus Elfring 2017-08-15 11:56 ` SF Markus Elfring 2017-08-15 11:58 ` [PATCH 1/5] net/9p: Delete an error message for a failed memory allocation in five functions SF Markus Elfring 2017-08-15 11:58 ` SF Markus Elfring 2017-08-15 12:00 ` [PATCH 2/5] net/9p: Improve 19 size determinations SF Markus Elfring 2017-08-15 12:00 ` SF Markus Elfring 2017-08-15 14:21 ` Al Viro 2017-08-15 14:21 ` Al Viro 2017-08-15 12:01 ` [PATCH 3/5] net/9p: Add a jump target in p9_client_walk() SF Markus Elfring 2017-08-15 12:01 ` SF Markus Elfring 2017-08-15 12:02 ` [PATCH 4/5] net/9p: Adjust a jump target in p9_client_attach() SF Markus Elfring 2017-08-15 12:02 ` SF Markus Elfring 2017-08-15 12:03 ` [PATCH 5/5] net/9p: Delete an unnecessary variable initialisation " SF Markus Elfring 2017-08-15 12:03 ` SF Markus Elfring
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.