]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-patches/0019-Update-for-cppcheck-v1.80.patch
buildsys: upload to pmg as well
[zfsonlinux.git] / zfs-patches / 0019-Update-for-cppcheck-v1.80.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Brian Behlendorf <behlendorf1@llnl.gov>
3 Date: Sat, 18 Nov 2017 14:08:00 -0800
4 Subject: [PATCH] Update for cppcheck v1.80
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Resolve new warnings and errors from cppcheck v1.80.
10
11 * [lib/libshare/libshare.c:543]: (warning)
12 Possible null pointer dereference: protocol
13 * [lib/libzfs/libzfs_dataset.c:2323]: (warning)
14 Possible null pointer dereference: srctype
15 * [lib/libzfs/libzfs_import.c:318]: (error)
16 Uninitialized variable: link
17 * [module/zfs/abd.c:353]: (error) Uninitialized variable: sg
18 * [module/zfs/abd.c:353]: (error) Uninitialized variable: i
19 * [module/zfs/abd.c:385]: (error) Uninitialized variable: sg
20 * [module/zfs/abd.c:385]: (error) Uninitialized variable: i
21 * [module/zfs/abd.c:553]: (error) Uninitialized variable: i
22 * [module/zfs/abd.c:553]: (error) Uninitialized variable: sg
23 * [module/zfs/abd.c:763]: (error) Uninitialized variable: i
24 * [module/zfs/abd.c:763]: (error) Uninitialized variable: sg
25 * [module/zfs/abd.c:305]: (error) Uninitialized variable: tmp_page
26 * [module/zfs/zpl_xattr.c:342]: (warning)
27 Possible null pointer dereference: value
28 * [module/zfs/zvol.c:208]: (error) Uninitialized variable: p
29
30 Convert the following suppression to inline.
31
32 * [module/zfs/zfs_vnops.c:840]: (error)
33 Possible null pointer dereference: aiov
34
35 Exclude HAVE_UIO_ZEROCOPY and HAVE_DNLC from analysis since
36 these macro's will never be defined until this functionality
37 is implemented.
38
39 Reviewed-by: George Melikov <mail@gmelikov.ru>
40 Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
41 Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
42 Closes #6879
43 (cherry picked from commit aebc5df418cb52cc2ec9fa6c9c147ca3b048bc49)
44 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
45 ---
46 Makefile.am | 6 +++---
47 lib/libshare/libshare.c | 37 ++++---------------------------------
48 lib/libzfs/libzfs_dataset.c | 4 +++-
49 lib/libzfs/libzfs_import.c | 2 +-
50 module/zfs/abd.c | 18 +++++++++---------
51 module/zfs/zfs_vnops.c | 1 +
52 module/zfs/zpl_xattr.c | 2 +-
53 module/zfs/zvol.c | 2 +-
54 8 files changed, 23 insertions(+), 49 deletions(-)
55
56 diff --git a/Makefile.am b/Makefile.am
57 index e46ac2dbe..508d3f40e 100644
58 --- a/Makefile.am
59 +++ b/Makefile.am
60 @@ -65,10 +65,10 @@ lint: cppcheck paxcheck
61
62 cppcheck:
63 @if type cppcheck > /dev/null 2>&1; then \
64 - cppcheck --quiet --force --error-exitcode=2 \
65 + cppcheck --quiet --force --error-exitcode=2 --inline-suppr \
66 --suppressions-list=.github/suppressions.txt \
67 - -UHAVE_SSE2 -UHAVE_AVX512F \
68 - ${top_srcdir}; \
69 + -UHAVE_SSE2 -UHAVE_AVX512F -UHAVE_UIO_ZEROCOPY \
70 + -UHAVE_DNLC ${top_srcdir}; \
71 fi
72
73 paxcheck:
74 diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c
75 index aa565ca82..022df016f 100644
76 --- a/lib/libshare/libshare.c
77 +++ b/lib/libshare/libshare.c
78 @@ -493,20 +493,10 @@ int
79 sa_enable_share(sa_share_t share, char *protocol)
80 {
81 sa_share_impl_t impl_share = (sa_share_impl_t)share;
82 - int rc, ret;
83 - boolean_t found_protocol;
84 + int rc, ret = SA_OK;
85 + boolean_t found_protocol = B_FALSE;
86 sa_fstype_t *fstype;
87
88 -#ifdef DEBUG
89 - fprintf(stderr, "sa_enable_share: share->sharepath=%s, protocol=%s\n",
90 - impl_share->sharepath, protocol);
91 -#endif
92 -
93 - assert(impl_share->handle != NULL);
94 -
95 - ret = SA_OK;
96 - found_protocol = B_FALSE;
97 -
98 fstype = fstypes;
99 while (fstype != NULL) {
100 if (protocol == NULL || strcmp(fstype->name, protocol) == 0) {
101 @@ -534,18 +524,10 @@ int
102 sa_disable_share(sa_share_t share, char *protocol)
103 {
104 sa_share_impl_t impl_share = (sa_share_impl_t)share;
105 - int rc, ret;
106 - boolean_t found_protocol;
107 + int rc, ret = SA_OK;
108 + boolean_t found_protocol = B_FALSE;
109 sa_fstype_t *fstype;
110
111 -#ifdef DEBUG
112 - fprintf(stderr, "sa_disable_share: share->sharepath=%s, protocol=%s\n",
113 - impl_share->sharepath, protocol);
114 -#endif
115 -
116 - ret = SA_OK;
117 - found_protocol = B_FALSE;
118 -
119 fstype = fstypes;
120 while (fstype != NULL) {
121 if (protocol == NULL || strcmp(fstype->name, protocol) == 0) {
122 @@ -696,11 +678,6 @@ sa_parse_legacy_options(sa_group_t group, char *options, char *proto)
123 {
124 sa_fstype_t *fstype;
125
126 -#ifdef DEBUG
127 - fprintf(stderr, "sa_parse_legacy_options: options=%s, proto=%s\n",
128 - options, proto);
129 -#endif
130 -
131 fstype = fstypes;
132 while (fstype != NULL) {
133 if (strcmp(fstype->name, proto) != 0) {
134 @@ -787,12 +764,6 @@ sa_zfs_process_share(sa_handle_t handle, sa_group_t group, sa_share_t share,
135 sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
136 sa_share_impl_t impl_share = (sa_share_impl_t)share;
137
138 -#ifdef DEBUG
139 - fprintf(stderr, "sa_zfs_process_share: mountpoint=%s, proto=%s, "
140 - "shareopts=%s, sourcestr=%s, dataset=%s\n", mountpoint, proto,
141 - shareopts, sourcestr, dataset);
142 -#endif
143 -
144 return (process_share(impl_handle, impl_share, mountpoint, NULL,
145 proto, shareopts, NULL, dataset, B_FALSE));
146 }
147 diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
148 index d6e85024d..b65dbc826 100644
149 --- a/lib/libzfs/libzfs_dataset.c
150 +++ b/lib/libzfs/libzfs_dataset.c
151 @@ -2244,8 +2244,10 @@ static void
152 get_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source,
153 char *statbuf, size_t statlen)
154 {
155 - if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY)
156 + if (statbuf == NULL ||
157 + srctype == NULL || *srctype == ZPROP_SRC_TEMPORARY) {
158 return;
159 + }
160
161 if (source == NULL) {
162 *srctype = ZPROP_SRC_NONE;
163 diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c
164 index 8b5222475..39c067293 100644
165 --- a/lib/libzfs/libzfs_import.c
166 +++ b/lib/libzfs/libzfs_import.c
167 @@ -309,7 +309,7 @@ zpool_label_disk_wait(char *path, int timeout_ms)
168 dev = udev_device_new_from_subsystem_sysname(udev,
169 "block", sysname);
170 if ((dev != NULL) && udev_device_is_ready(dev)) {
171 - struct udev_list_entry *links, *link;
172 + struct udev_list_entry *links, *link = NULL;
173
174 ret = 0;
175 links = udev_device_get_devlinks_list_entry(dev);
176 diff --git a/module/zfs/abd.c b/module/zfs/abd.c
177 index 765ac7fb7..138b041c8 100644
178 --- a/module/zfs/abd.c
179 +++ b/module/zfs/abd.c
180 @@ -250,7 +250,7 @@ abd_alloc_pages(abd_t *abd, size_t size)
181 struct list_head pages;
182 struct sg_table table;
183 struct scatterlist *sg;
184 - struct page *page, *tmp_page;
185 + struct page *page, *tmp_page = NULL;
186 gfp_t gfp = __GFP_NOWARN | GFP_NOIO;
187 gfp_t gfp_comp = (gfp | __GFP_NORETRY | __GFP_COMP) & ~__GFP_RECLAIM;
188 int max_order = MIN(zfs_abd_scatter_max_order, MAX_ORDER - 1);
189 @@ -334,12 +334,12 @@ abd_alloc_pages(abd_t *abd, size_t size)
190 static void
191 abd_alloc_pages(abd_t *abd, size_t size)
192 {
193 - struct scatterlist *sg;
194 + struct scatterlist *sg = NULL;
195 struct sg_table table;
196 struct page *page;
197 gfp_t gfp = __GFP_NOWARN | GFP_NOIO;
198 int nr_pages = abd_chunkcnt_for_bytes(size);
199 - int i;
200 + int i = 0;
201
202 while (sg_alloc_table(&table, nr_pages, gfp)) {
203 ABDSTAT_BUMP(abdstat_scatter_sg_table_retry);
204 @@ -370,11 +370,11 @@ abd_alloc_pages(abd_t *abd, size_t size)
205 static void
206 abd_free_pages(abd_t *abd)
207 {
208 - struct scatterlist *sg;
209 + struct scatterlist *sg = NULL;
210 struct sg_table table;
211 struct page *page;
212 int nr_pages = ABD_SCATTER(abd).abd_nents;
213 - int order, i;
214 + int order, i = 0;
215
216 if (abd->abd_flags & ABD_FLAG_MULTI_ZONE)
217 ABDSTAT_BUMPDOWN(abdstat_scatter_page_multi_zone);
218 @@ -543,8 +543,8 @@ abd_verify(abd_t *abd)
219 ASSERT3P(abd->abd_u.abd_linear.abd_buf, !=, NULL);
220 } else {
221 size_t n;
222 - int i;
223 - struct scatterlist *sg;
224 + int i = 0;
225 + struct scatterlist *sg = NULL;
226
227 ASSERT3U(ABD_SCATTER(abd).abd_nents, >, 0);
228 ASSERT3U(ABD_SCATTER(abd).abd_offset, <,
229 @@ -749,8 +749,8 @@ abd_get_offset_impl(abd_t *sabd, size_t off, size_t size)
230 abd->abd_u.abd_linear.abd_buf =
231 (char *)sabd->abd_u.abd_linear.abd_buf + off;
232 } else {
233 - int i;
234 - struct scatterlist *sg;
235 + int i = 0;
236 + struct scatterlist *sg = NULL;
237 size_t new_offset = sabd->abd_u.abd_scatter.abd_offset + off;
238
239 abd = abd_alloc_struct();
240 diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c
241 index 6a1dab5c9..6f6ce79db 100644
242 --- a/module/zfs/zfs_vnops.c
243 +++ b/module/zfs/zfs_vnops.c
244 @@ -836,6 +836,7 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
245 aiov->iov_base != abuf->b_data)) {
246 ASSERT(xuio);
247 dmu_write(zfsvfs->z_os, zp->z_id, woff,
248 + /* cppcheck-suppress nullPointer */
249 aiov->iov_len, aiov->iov_base, tx);
250 dmu_return_arcbuf(abuf);
251 xuio_stat_wbuf_copied();
252 diff --git a/module/zfs/zpl_xattr.c b/module/zfs/zpl_xattr.c
253 index 0c626b122..ebb6e7be2 100644
254 --- a/module/zfs/zpl_xattr.c
255 +++ b/module/zfs/zpl_xattr.c
256 @@ -333,7 +333,7 @@ zpl_xattr_get_sa(struct inode *ip, const char *name, void *value, size_t size)
257 if (error)
258 return (error);
259
260 - if (!size)
261 + if (size == 0 || value == NULL)
262 return (nv_size);
263
264 if (size < nv_size)
265 diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c
266 index 5293f95fb..aac494209 100644
267 --- a/module/zfs/zvol.c
268 +++ b/module/zfs/zvol.c
269 @@ -202,7 +202,7 @@ static zvol_state_t *
270 zvol_find_by_name_hash(const char *name, uint64_t hash, int mode)
271 {
272 zvol_state_t *zv;
273 - struct hlist_node *p;
274 + struct hlist_node *p = NULL;
275
276 mutex_enter(&zvol_state_lock);
277 hlist_for_each(p, ZVOL_HT_HEAD(hash)) {
278 --
279 2.14.2
280