slip: make slhc_free() silently accept an error pointer [Linux 5.1]

slip: make slhc_free() silently accept an error pointer [Linux 5.1]

This Linux kernel change "slip: make slhc_free() silently accept an error pointer" is included in the Linux 5.1 release. This change is authored by Linus Torvalds <torvalds [at] linux-foundation.org> on Thu Apr 25 16:13:58 2019 -0700. The commit for this change in Linux stable tree is baf76f0 (patch).

slip: make slhc_free() silently accept an error pointer

This way, slhc_free() accepts what slhc_init() returns, whether that is
an error or not.

In particular, the pattern in sl_alloc_bufs() is

        slcomp = slhc_init(16, 16);
        ...
        slhc_free(slcomp);

for the error handling path, and rather than complicate that code, just
make it ok to always free what was returned by the init function.

That's what the code used to do before commit 4ab42d78e37a ("ppp, slip:
Validate VJ compression slot parameters completely") when slhc_init()
just returned NULL for the error case, with no actual indication of the
details of the error.

Reported-by: [email protected]
Fixes: 4ab42d78e37a ("ppp, slip: Validate VJ compression slot parameters completely")
Acked-by: Ben Hutchings <[email protected]>
Cc: David Miller <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/slip/slhc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
index f4e93f5..ea90db3 100644
--- a/drivers/net/slip/slhc.c
+++ b/drivers/net/slip/slhc.c
@@ -153,7 +153,7 @@ struct slcompress *
 void
 slhc_free(struct slcompress *comp)
 {
-   if ( comp == NULLSLCOMPR )
+   if ( IS_ERR_OR_NULL(comp) )
        return;

    if ( comp->tstate != NULLSLSTATE )

Leave a Reply

Your email address will not be published. Required fields are marked *