From 3a42518042b36ad90950a3abf0aa125c0342b2c4 Mon Sep 17 00:00:00 2001 From: unclejack Date: Wed, 14 Dec 2016 22:36:58 +0200 Subject: [PATCH] daemon: return directly without ifs where possible Signed-off-by: Cristian Staretu --- daemon/daemon_windows.go | 5 +---- daemon/graphdriver/devmapper/deviceset.go | 16 +++------------- daemon/graphdriver/windows/windows.go | 6 +----- daemon/logger/etwlogs/etwlogs_windows.go | 5 +---- daemon/logger/fluentd/fluentd.go | 7 ++----- daemon/logger/gelf/gelf.go | 7 ++----- 6 files changed, 10 insertions(+), 36 deletions(-) diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 36f0d7fb16..2c79544704 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -204,10 +204,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes. w, err := verifyContainerResources(&hostConfig.Resources, hyperv) warnings = append(warnings, w...) - if err != nil { - return warnings, err - } - return warnings, nil + return warnings, err } // platformReload update configuration with platform specific options diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go index b8e762592c..f4ac1bde1e 100644 --- a/daemon/graphdriver/devmapper/deviceset.go +++ b/daemon/graphdriver/devmapper/deviceset.go @@ -380,10 +380,7 @@ func (devices *DeviceSet) isDeviceIDFree(deviceID int) bool { var mask byte i := deviceID % 8 mask = (1 << uint(i)) - if (devices.deviceIDMap[deviceID/8] & mask) != 0 { - return false - } - return true + return (devices.deviceIDMap[deviceID/8] & mask) == 0 } // Should be called with devices.Lock() held. @@ -1400,10 +1397,7 @@ func (devices *DeviceSet) saveTransactionMetaData() error { } func (devices *DeviceSet) removeTransactionMetaData() error { - if err := os.RemoveAll(devices.transactionMetaFile()); err != nil { - return err - } - return nil + return os.RemoveAll(devices.transactionMetaFile()) } func (devices *DeviceSet) rollbackTransaction() error { @@ -2408,11 +2402,7 @@ func (devices *DeviceSet) UnmountDevice(hash, mountPath string) error { } logrus.Debug("devmapper: Unmount done") - if err := devices.deactivateDevice(info); err != nil { - return err - } - - return nil + return devices.deactivateDevice(info) } // HasDevice returns true if the device metadata exists. diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index beac93ae75..254cc3aeb0 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -775,11 +775,7 @@ func (d *Driver) resolveID(id string) (string, error) { // setID stores the layerId in disk. func (d *Driver) setID(id, altID string) error { - err := ioutil.WriteFile(filepath.Join(d.dir(id), "layerId"), []byte(altID), 0600) - if err != nil { - return err - } - return nil + return ioutil.WriteFile(filepath.Join(d.dir(id), "layerId"), []byte(altID), 0600) } // getLayerChain returns the layer chain information. diff --git a/daemon/logger/etwlogs/etwlogs_windows.go b/daemon/logger/etwlogs/etwlogs_windows.go index a78c02c99d..b3da50f915 100644 --- a/daemon/logger/etwlogs/etwlogs_windows.go +++ b/daemon/logger/etwlogs/etwlogs_windows.go @@ -155,8 +155,5 @@ func callEventWriteString(message string) error { func callEventUnregister() bool { ret, _, _ := procEventUnregister.Call(uintptr(providerHandle)) - if ret != win32CallSuccess { - return false - } - return true + return ret == win32CallSuccess } diff --git a/daemon/logger/fluentd/fluentd.go b/daemon/logger/fluentd/fluentd.go index a8303cf97b..ef4da99f70 100644 --- a/daemon/logger/fluentd/fluentd.go +++ b/daemon/logger/fluentd/fluentd.go @@ -182,11 +182,8 @@ func ValidateLogOpt(cfg map[string]string) error { } } - if _, err := parseAddress(cfg["fluentd-address"]); err != nil { - return err - } - - return nil + _, err := parseAddress(cfg["fluentd-address"]) + return err } func parseAddress(address string) (*location, error) { diff --git a/daemon/logger/gelf/gelf.go b/daemon/logger/gelf/gelf.go index 4dedb2d4c1..3e1877a60a 100644 --- a/daemon/logger/gelf/gelf.go +++ b/daemon/logger/gelf/gelf.go @@ -172,11 +172,8 @@ func ValidateLogOpt(cfg map[string]string) error { } } - if _, err := parseAddress(cfg["gelf-address"]); err != nil { - return err - } - - return nil + _, err := parseAddress(cfg["gelf-address"]) + return err } func parseAddress(address string) (string, error) {